I've been thinking about it for a while and, after asking a question on vi.stackexchange, I decided to write a small plugin myself and put it on GitHub; basically it offers a mapping to activate a kind of "window movement" mode where Vim waits for inputs that it appends to Ctrl+w, so that one does not have to press this combination before every window-related movement or action; hitting Esc exits this mode.
It's mostly just one main function and one mapping, so I will copy them below.
- The mapping plus some things I copied from scratch.vim which seemed reasonable:
" plugin/winzoz.vim
if (exists('g:winzoz_disable') && g:winzoz_disable) || &compatible
finish
endif
nnoremap <silent> <Plug>(go-zoz-navigation) :call winzoz#goZoZ()<cr>
if !exists('g:winzoz_no_mappings')
nmap <silent> <leader>w <Plug>(go-zoz-navigation)
endif
- The function with the logic (plus a helper function for coloring the command line while the functionality is active)
" autoload/winzoz.vim
function! winzoz#goZoZ()
redrawstatus!
echohl Search
echo s:make_status_line()
echohl None
let l:key = ''
while l:key !=? "\<Esc>"
let l:key = nr2char(getchar())
execute "normal! \<c-w>" . l:key
redrawstatus!
endw
echo ''
redrawstatus!
endfunction
" drawing function
function! s:make_status_line()
let l:text = 'Go WinZoZ'
let l:text .= repeat(' ', (&columns - len(l:text))/2)
return repeat(' ', &columns - len(l:text) - 1) . l:text
endfunction
I'd like some feedback in general, but also on the following points.
- As regards the logic, I'm not checking that the input is correct (with a
:try
-:catch
-:finally
), because I'm not inventing any functionality, but only forwarding the keys to the already existing functionality of Ctrl+w+whatever. - I'm using
echohl Search
+echo
to print a colored command line to make apparent when the mode is active; is this a good way of doing it?- Regarding this part, I had to make a trick (the
- 1
in the second to last line of code above) in order to have one character left for the blinking cursor. I really don't like this, but I don't know what else I could do...
- Regarding this part, I had to make a trick (the
- There are some Ctrl+w-commands that take two key strokes, but my plugin cannot deal with them :( ... I'll fix when I have time.
- Do you like it?
- Do you think it could be useful?
(I also plan to add some documentation to it, fwiw :/ )