vimdiff and move among left and right pane - vim

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

Related

switching windows with <leader> instead of ctrl

I recently start using leader key in vim, and mapped to space
Earlier I use window switching with ctrl + {h, j, k, l}
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
And now I was trying something like
nnoremap <leader>h <C-w>h
nnoremap <leader>j <C-w>j
nnoremap <leader>k <C-w>k
nnoremap <leader>l <C-w>l
I already remove any prior mapping with the above mentioned key.
Now issue I am facing is, with ctrl key i can switch the window panes without lifting finger from ctrl While with space I have to press Leader and {h, j, k, l} simultaneously and then I have to press leader and {h, j, k, l} if want to go to some other window pane.
What I am trying to say is, let say my window vertically split b/w two and I wish to go to second window and come back to original.
With ctrl key: ctrl + l + h
with leader key: space + l, space + h
I want my leader key work exact same as ctrl, since it is convenient to use
Is this possible?
Also If you have some advice for newbie like me, I will be glad to hear it.
What you call "leader key" is not a special key at all and certainly not a modifier, like Ctrl, Shift, or Alt so you can't make it work like one. Unless they involve one of those modifiers, Vim mappings are always sequential: you press the first key, then the second one, etc.
If you absolutely want chord-like mappings, you could try arpeggio.

Ctrl + w + w obviously cannot perform to switch tab on a google compute engine window

Ctrl + w is a shortcut to closing an open window on VM instance of Google Compute Engine. Hence it will ask to perform that action before letting me type one more w, to enact switching of tabs between the directory tree and the script to work on in vim.
I've tried the following, as mentioned here
map <C-l> :tabn<CR>
map <C-h> :tabp<CR>
map <C-n> :tabnew<CR>
While I'm not sure what tabn and tabp indicate, I tried the first two line and (C as Ctrl) neither of these respond to anything new. I used source ~/.vimrc command before expecting a change is reflected. What is wrong here?
I think you're mixing up Vim tabs and Vim windows.
Vim windows will split the screen vertically or horizontally into separate panes, which are all visible at the same time. That's typically used by directory tree plug-ins which want to display a navigator on a sidebar.
Vim tabs group a set of windows, so that you can switch between whole sets of windows at once and still easily go back to where you were before. (People often use tabs to work on different projects and switch between them, though opening one file per tab, fullscreen, is also a somewhat common workflow.)
The mappings that use Control-W are window mappings, not tab mappings. (You can switch to next tab with gt and previous tab with gT).
The normal commands to cycle windows are Ctrl-W w (to move right/down) and Ctrl-W W (to move left/up), so you can use these two mappings:
nnoremap <C-l> <C-w>w
nnoremap <C-h> <C-w>W
If you want a mapping to open a new window with a new blank file, you can use:
nnoremap <C-n> <C-w>n
If your problem is with typing Control-W in specific, perhaps a better option is to map a key sequence you're not using to replace Control-W, but keep it to just the prefix, so that all other commands that follow are still available?
Perhaps use Control-Q, which is just next to W in the keyboard:
nmap <C-Q> <C-W>
And you might want to remap the commands that use the same key twice, so in your case use Q twice where there's two W's:
nmap <C-Q> <C-W>
nnoremap <C-Q>q <C-W>w
nnoremap <C-Q>Q <C-W>W
nnoremap <C-Q><C-Q> <C-W><C-W>
Those four there, that would be my recommendation, if Control-W is an inconvenient sequence for you.

Arrow key mappings do not function

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 ??

Vim: Changing viewports quickly in normal mode

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.

easier way to navigate between vim split panes

I am using NERDTree on vim and usually open files with i
Is there an easy way to switch between different panes? Currently I use CTRL+W+W to move from one pane to another.
Long ago I found a tip (once on vim.org, now on wikia, apparently) that I've stuck with. Remap ctrl-[hjkl] to navigate splits. It has served me well.
" Use ctrl-[hjkl] to select the active split!
nmap <silent> <c-k> :wincmd k<CR>
nmap <silent> <c-j> :wincmd j<CR>
nmap <silent> <c-h> :wincmd h<CR>
nmap <silent> <c-l> :wincmd l<CR>
I prefer hitting single keys over hitting key-chords. The following maps pane movement to arrow keys:
" Smart way to move between panes
map <up> <C-w><up>
map <down> <C-w><down>
map <left> <C-w><left>
map <right> <C-w><right>
I know this is an old question, but I have a perfect way. Using the number of the split.
split_number C-w C-w
The panes are numbered from top-left to bottom-right with the first one getting the number 1.
for example to go to split number 3 do this 3 C-w C-w, press Ctrl-w twice.
Key mappings are definitely the way to go. I use the mappings mentioned by overthink. I also include the following mappings in my vimrc to move the splits themselves.
" Move the splits arround!
nmap <silent> <c-s-k> <C-W>k
nmap <silent> <c-s-j> <C-W>j
nmap <silent> <c-s-h> <C-W>h
nmap <silent> <c-s-l> <C-W>l
This makes it so that if the split opens in the wrong spot (lets say the left side and I want it on the right) I go to that split and hit <C-S-l> and the split moves where I want it to.
In order to be consistent with changing tabs via gt & gT, I'm currently trying out the g mappings for changing splits. I tend to hit the shift key as I go for the Ctrl key so this helps me avoid that mistake until I get better at not doing so.
nnoremap gh <C-W><C-H>
nnoremap gj <C-W><C-J>
nnoremap gk <C-W><C-K>
nnoremap gl <C-W><C-L>
I have mapped ctrl+w ctrl+w to <tab> (under normal mode as in normal mode tab does not have any use)and that's have made my life easier as now I can switch between panes easily by pressing <tab>.
For switching to a particular pane, I can press <i> + <tab> to switch between panes as split window panes also got their own number which can replace i.
Ex. i = 1,2...n.
Very easy way of achieving it. Type this shortcut twice, and that should work
ctrl+w ctrl+w

Resources