Well,
One can use <C-w>[hjkl] to move between window, and it's works!
Then I shortcut the horizontal moves like noremap <S-RIGHT> <C-W>l, and it's works!
But, when I try to shortcut the vertical moves, I use noremap <S-UP> <C-W>k and noremap <S-DOWN> <C-W>j, and it doesn't work!
Any suggestions?
EDIT : Assuming than the terminal handles the <S-UP> and <S-DOWN>, which conflict with my vim (or whatever term app) preferences, is there any way to force the terminal to forget this mapping ??
Related
I want to remap default cursor movement keys (hjkl) to Colemak's on same places (hnei) + alt, just as described here: https://forum.colemak.com/topic/50-colemak-vim/p6/
This is what was typed to .vimrc (which lies in correct directory, I checked):
" Colemak hjkl hack
nnoremap <A-h> <Left>|
nnoremap <A-n> <Down>|
nnoremap <A-e> <Up>|
nnoremap <A-i> <Right>|
I have already tried to:
Remove "|"s
Switch between and
Use hjkl instead of <Left><Down><Up><Right>
Use "noremap" instead of "nnoremap",
Nothing happens. What is wrong?
<esc>h instead of <A-h> works, thanks to Ralf
I am using vimdiff for the first time. Online I found written that to move from the left pane you use CTRL + w + Left or right arrow
This does not work for me. But I see that if I press just CTRL + w and press w for a sec and let it go, it switches pane after ~500ms.
Is this how it is supposed to work? Am I doing something wrong?
Ctrl+w and right and left arrow can be used to move between any split windows on vim, not only vimdiff splits.
These keys do work here on cygwin; also, Ctrl+w w also moves to the next window, but without the delay you mentioned.
It is possible that you have mapped these keys in your .vimrc or via some vim plugin. You can check this with :map w, :map <left> and :map <right>.
As moving between windows is something that you use often, you may consider using the following mappings:
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
nnoremap <C-H> <C-W>h
nnoremap <C-L> <C-W>l
Then you can use Ctrl+h and Ctrl+l to move left and right, without moving your hands from the home row. And the nnoremap will ensure that these works despite of any other mappings that you may have.
Press Ctrl + W and then (after releasing Ctrl + W) press the arrow keys to change the pane.
It is very useful to use set mouse=a in your .vimrc file. It gives you possibility to switch between windows using mouse. Additionally you can resize windows using it.
If you prefer to use keyboard I have also mapped arrow keys in .vimrc in this way:
map <C-Left> <C-W>j
map <C-Down> <C-W>k
map <C-Up> <C-W>h
map <C-Right> <C-W>l
To move among left and right pane, Press ctrl+w and then ctrl+r. This is both left and right vice-versa.
You can also use :wincmd w for next window, and :wincmd W for previous window.
The :wincmd is especially useful when ctrl+w is captured by the environment. For example see: https://stackoverflow.com/a/73749587/811335
I use viewports extensively in vim, I'm forever splitting files into new viewports etc. I typically navigate around the viewports using Ctrl+W and a movement key, ie: hjkl.
Since there is a normal mode command for switching tabs quickly, gt, gT and ^gt, I was wondering if there is a normal mode equivalent without the modifier. If not, what would a good mapping be? gv and gw are both taken already.
For switching viewports quickly, I use the following:
noremap <C-J> <C-W>j<CR>
noremap <C-K> <C-W>k<CR>
noremap <C-H> <C-W>h<CR>
noremap <C-L> <C-W>l<CR>
I have the following mappings:
map <tab> <c-w>
map <tab><tab> <c-w><c-w>
so I can move quickly between windows with <tab>j, <tab>k, etc...
Note that this also make easier to use all the other <c-w> mappings like <c-w>t to go to the first window or <c-w>b to go to the last window.
These just become <tab>t and <tab>b.
Before using these mappings I was using
map ,w <c-w>
so again you would use this followed by a letter to move around the windows.
If you just want to stick to left, right, up and down then you can directly
use something like
map ,l <c-w>l
and so on.
I am a long time emacs user learning Vim. Emacs lets me navigate in the mini-buffer (where I issue commands like C-x C-s) using the same navigation keyboard shortcuts as in any other buffer. For example, I can navigate forward one character using C-f, even while in the mini-buffer. I could also use the arrow keys, but they are too far away.
Is there any keyboard shortcut to navigate in Vim's command mode (:), without using the arrow keys -- equivalent to emacs C-f, C-b? Thanks.
Adding to Greg Hewgill's answer, you can use q: to open the command-line window, where you have any Vim editing power at your hand.
Some from the Vim help:
CTRL-B or <Home>
cursor to beginning of command-line
CTRL-E or <End>
cursor to end of command-line
CTRL-H
<BS> Delete the character in front of the cursor (see |:fixdel| if
your <BS> key does not do what you want).
<Del> Delete the character under the cursor (at end of line:
character before the cursor).
CTRL-W Delete the |word| before the cursor. This depends on the
'iskeyword' option.
CTRL-U Remove all characters between the cursor position and
the beginning of the line.
I have these in my .vimrc
cnoremap <C-a> <Home>
cnoremap <C-e> <End>
cnoremap <C-p> <Up>
cnoremap <C-n> <Down>
cnoremap <C-b> <Left>
cnoremap <C-f> <Right>
cnoremap <M-b> <S-Left>
cnoremap <M-f> <S-Right>
With the default key bindings, vim does not offer non-arrow-key navigation of the command line editing. However, see :help cmdline-editing for an example of how to use the :cnoremap command to set up alternate key bindings.
I achieved that with <C-p> and <C-n> to navigate previous and next commands respectively.
P.S I'm not making any custom binding like Tassos did.
I'm trying to set up the NERDComment plugin in vim, but I'm having some trouble with the keys. I'd like to set the basic toggle functionality (comment a line if it's uncommented, uncomment if it's commented) to be c. The problem is that I've remapped the Leader to be ,, which is the same key that NERD wants for all of it's hotkeys. Anyone have any idea as to how to set this up?
Just call NERDComment function in your mapping. For example, my mapping to comment the current line:
inoremap ,c <C-o>:call NERDComment(0,"toggle")<C-m>
Here's a breakdown of how this vim remap works.
The i in inoremap means that the remap only applies in insert mode.
The noremap means that the remap can't be overridden later in your .vimrc file by accident, or by a plugin.
The ,c is the key combination that triggers the key map.
The <C-o> temporarily takes you out of insert mode for one command, so the next section of the remap can call the NERDComment function.
The :call NERDComment(0,"toggle") is the NERDComment function being called.
Then <C-m> is another way of saying carriage return, which executes the command.
If you want the comment shortcut to work in normal mode and visual mode, but not in insert mode where it might do something weird when you try to type a comma, you can use the following remaps:
nnoremap ,c :call NERDComment(0,"toggle")<CR>
vnoremap ,c :call NERDComment(0,"toggle")<CR>
documented method of remapping key is located here:
remapping documentation
reference
map <leader>d <Plug>NERDCommenterToggle
"silently rejects remap will not work
nnoremap <leader>d <Plug>NERDCommenterToggle
I fell into the pitfall of attempting to use "nnoremap" to remap on my first attempt resulting in unresponsive mapping. You must use "map", "nmap", etc to properly remap the function
:map <C-z> <plug>NERDCommenterToggle
Maps 'toggle comments' to ctrl+z