0
votes

I am working with split windows in vim, but I am having trouble navigating and resizing split windows.

I have added these mappings to my .vimrc text file:

nmap <silent> <A-Up> :wincmd k<CR>
nmap <silent> <A-Down> :wincmd j<CR>
nmap <silent> <A-Left> :wincmd h<CR>
nmap <silent> <A-Right> :wincmd l<CR>

But still, when pressing <A-Left> it does not move window. Also I am using <C-w> +, but the windows do not resize! I also tried <C-w> <, but it resizes like 1 pixel at a time! Is there any faster way to resize split windows?

2

2 Answers

1
votes

10 Ctrl-W+ increases the window size by 10 lines. To resize all Windows to the same size, you can use CTRL-W = and to increase a window to its maximum size, use Ctrl-W _.

To resize in different steps, you can create maps that will adjust the window size differently. For example to increase the window size by a factor of 1.5 and decrease the window size by 0.67, you can map this:

 nnoremap <silent> <Leader>+ :exe "resize " . (winheight(0) * 3/2)<CR>
 nnoremap <silent> <Leader>- :exe "resize " . (winheight(0) * 2/3)<CR>

Alternatively you can use the :resize command to change the height of the window, to change the window width, use the :vertical modifier. So to resize by 10 lines, use:

:res +10
:res -10

as for navigation try

 nnoremap <C-h> <C-w>h
 nnoremap <C-j> <C-w>j
 nnoremap <C-k> <C-w>k
 nnoremap <C-l> <C-w>l
1
votes

The <C-W> commands resize by individual lines / columns (pixels wouldn't even be possible in console Vim), but you are supposed to prepend a number before them to change larger amounts at once. (A lot of Vim commands take such a [count], as it's called in the help.)


For the <A-Up> mappings, do they work in graphical GVIM, but not in the console?! The mapping definitions look fine (but you should use :nnoremap).

Due to the way that the keyboard input is handled internally, some key combinations, like Ctrl + non-alphabetic cannot be mapped, and Ctrl + letter vs. Ctrl + Shift + letter cannot be distinguished. (Unless your terminal sends a distinct termcap code for it, which most don't.) In insert or command-line mode, try typing the key combination. If nothing happens / is inserted, you cannot use that key combination. This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.

Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals, cp. http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa4588b32a/bfbcb22f37a8a1f8

But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.