Created
December 30, 2011 09:52
-
-
Save AndrewRadev/1539062 to your computer and use it in GitHub Desktop.
Execute window commands in Vim with the possibility of repeating them, "."-style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nnoremap _w :Wincmd<cr> | |
nnoremap _. :WincmdRepeat<cr> | |
command! Wincmd call s:Wincmd('') | |
function! s:Wincmd(cmd_count) | |
let cmd_count = a:cmd_count | |
" echo the command so far for some visual feedback | |
redraw | echo cmd_count.'wincmd' | |
" wait for a keypress from the user | |
let char = nr2char(getchar()) | |
if char =~ '\d' | |
" then it's a digit, add it to "cmd_count" and ask again | |
let cmd_count = cmd_count.char | |
return s:Wincmd(cmd_count) | |
else | |
" it's a window command, save it and carry on | |
let cmd = char | |
endif | |
" build up the full window command | |
let wincmd = cmd_count.'wincmd '.cmd | |
" save the command to be able to repeat it later | |
let g:wincmd_repeat = wincmd | |
" execute the command and show it to the user | |
exe wincmd | |
redraw | echo wincmd | |
endfunction | |
command! WincmdRepeat call s:WincmdRepeat() | |
function! s:WincmdRepeat() | |
if exists('g:wincmd_repeat') | |
exe g:wincmd_repeat | |
echo g:wincmd_repeat | |
endif | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment