I have in my .vimrc some simple mappings to resize split windows easily:

noremap <Leader><UP>    <C-w>+
noremap <Leader><DOWN>  <C-w>-

That works pretty fine but for example, when I want to resize the window of 10 lines I have to press and release Leader+UP 10 times.

How can I repeat this mapping while the keys are pressed? What I want is when I press Leader+UP the mapping will be applied once then after a short duration it will be applied once again and so on while I hold the keys.

Note: I know it is possible to prefix <C-w>+ with a count and I could hardcode it in the mapping or simply input a count before using the mapping but that's not how I want to do it.

Note2: I also know that a popular mapping to resize windows is to use + and - keys which are easier to press several times but I don't want to use those keys to do that neither.


You could try entering a ... Vim submode! For your case, something like this:

call submode#enter_with('grow/shrink', 'n', '', '<leader><up>', '<C-w>+')
call submode#enter_with('grow/shrink', 'n', '', '<leader><down>', '<C-w>-')
call submode#map('grow/shrink', 'n', '', '<down>', '<C-w>-')
call submode#map('grow/shrink', 'n', '', '<up>', '<C-w>+')

This means, you enter the submode with Leader-Up or Leader-Down (which will also grow/shrink the window once) and then - you'll only have to press Up or Down to grow/shrink the window, until you exit the submode.

See also the help, for timeout issues, but, to disable it:

"disable submode timeouts:
let g:submode_timeout = 0

... which means you'll stay in that submode indefinitely, until you press a key other than Up or Down, or until you hit Esc.

Aaand, the next useful tip I'd recommend:

" don't consume submode-leaving key
let g:submode_keep_leaving_key = 1

... which allows you to move directly to your next commands, when pressing a different key. For instance, pressing : will both leave the submode and open the command line.

  • I tried you solution but it doesn't seem to work: When I hit <kbd>Leader</kbd>+<kbd>UP</kbd> I have the message --submode: grow/shrink -- and the window is resized by one line but the command isn't repeated. I tried it with the 4 combinaisons of g:submode_keep_leaving_key and g:submode_timeout to 0 or 1. I'm not sure if I did something wrong or not. I'm usually using vim in a terminal but for now I can only test with gVim on windows but I'm not sure it change something. – statox Jun 18 '15 at 13:13
  • 2
    The command is not auto-repeated, you still have to hit Up or Down yourself as many times as needed (but without having to press Leader first) – VanLaser Jun 18 '15 at 13:16
  • Oh I understand the code better now! It works perfectly thanks! – statox Jun 18 '15 at 13:20
  • 2
    Perfect answer and amazing plugin! (Note: you have to install the vim-submode plugin before adding the above commands to your ~/.vimrc.) – weibeld Sep 19 '17 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.