Por padrão, não há como fazer isso no vim porque o vim não controla o wincmd executado anteriormente. No entanto, é possível fazer isso através de alguns mapeamentos inteligentes:
function! s:Wincmd(count, key)
" If count is not zero, use the original count. If otherwise, don't
" include a count.
let if_count = a:count ? a:count : ""
" This builds a wincmd from the given key, and saves it so
" it can be repeated.
let g:last_wincmd = "wincmd " . nr2char(a:key)
" Execute the built wincmd
execute if_count . g:last_wincmd
endfunction
function! s:WincmdRepeat(count)
" If no wincmd has been executed yet, don't do anything
if !exists('g:last_wincmd') | return | endif
" If a count is given, repeat the last wincmd that amount of times.
" If otherwise, just repeat once.
let if_count = a:count ? a:count : ""
execute if_count . g:last_wincmd
endfunction
" Overwrite the default <C-w> mapping so that the last wincmd can be kept
" track of. The getchar function is what captures the key pressed
" directly afterwards. The <C-u> is to remove any cmdline range that vim
" automatically inserted.
nnoremap <silent> <C-w> :<C-u>call <SID>Wincmd(v:count, getchar())<CR>
" This just calls the function which repeats the previous wincmd. It
" does accept a count, which is the number of times it should repeat the
" previous wincmd. You can also replace Q with whatever key you want.
nnoremap <silent> Q :<C-u> call <SID>WincmdRepeat(v:count)<CR>
Observe que, se você tiver algum mapeamento em uso, <C-w>
ele só poderá ser repetido se não for da nore
variedade. Quaisquer wincmds emitidos usando :wincmd
não serão repetidos. Além disso, quaisquer wincmds que contenham mais de um caractere não podem ser executados (como <C-w>gf
) .
Tópicos de ajuda relevantes
:help v:count
:help getchar()
:help nr2char()
:help expr1
:help :wincmd
:help :execute
:help :for
:help :map-<silent>
:help c_CTRL-U
:help <SID>