Extend README.md to add more possibilities to use this plugin
Opened this issue · 8 comments
As a user it would be nice to have more suggestions in README.md how to extend other builtin motions and support third party motions.
Following list tries to be comprehensive w.r.t. built-in motions (grouped thematically, e.g. folds, spelling, horizontal movement, ...):
" include count in ; and , for fFtT which is not the case in default vim
for key in [ 'f', 'F', 't', 'T']
execute 'noremap <expr> '.key." repmo#ZapKey('".key."')|sunmap ".key
endfor
for keys in [ ['h', 'l'], ['w', 'b'], ['W', 'B'], ['e', 'ge'], ['E', 'gE'] ]
execute 'noremap <expr> '.keys[0]." repmo#SelfKey('".keys[0]."', '".keys[1]."')|sunmap ".keys[0]
execute 'noremap <expr> '.keys[1]." repmo#SelfKey('".keys[1]."', '".keys[0]."')|sunmap ".keys[1]
endfor
for keys in [ ['<C-E>', '<C-Y>'], ['<C-B>', '<C-F>'], ['<C-D>', '<C-U>'] ]
execute 'nmap <expr> '.keys[0]." repmo#SelfKey('".keys[0]."', '".keys[1]."')"
execute 'nmap <expr> '.keys[1]." repmo#SelfKey('".keys[1]."', '".keys[0]."')"
endfor
for keys in [ ['j', 'k'], ['gj', 'gk'], ['-', '+'] ]
execute 'noremap <expr> '.keys[0]." repmo#SelfKey('".keys[0]."', '".keys[1]."')|sunmap ".keys[0]
execute 'noremap <expr> '.keys[1]." repmo#SelfKey('".keys[1]."', '".keys[0]."')|sunmap ".keys[1]
endfor
for keys in [ ['(', ')'], ['{', '}'] ]
execute 'noremap <expr> '.keys[0]." repmo#SelfKey('".keys[0]."', '".keys[1]."')|sunmap ".keys[0]
execute 'noremap <expr> '.keys[1]." repmo#SelfKey('".keys[1]."', '".keys[0]."')|sunmap ".keys[1]
endfor
for keys in [ ['[[', ']]'], ['[]', ']['], ['[m', ']m'], ['[M', ']M'] ]
execute 'noremap <expr> '.keys[0]." repmo#SelfKey('".keys[0]."', '".keys[1]."')|sunmap ".keys[0]
execute 'noremap <expr> '.keys[1]." repmo#SelfKey('".keys[1]."', '".keys[0]."')|sunmap ".keys[1]
endfor
for keys in [ ['[{', ']}'], ['[(', '])'] ]
execute 'noremap <expr> '.keys[0]." repmo#SelfKey('".keys[0]."', '".keys[1]."')|sunmap ".keys[0]
execute 'noremap <expr> '.keys[1]." repmo#SelfKey('".keys[1]."', '".keys[0]."')|sunmap ".keys[1]
endfor
for keys in [ ['[c', ']c'] ]
execute 'noremap <expr> '.keys[0]." repmo#SelfKey('".keys[0]."', '".keys[1]."')|sunmap ".keys[0]
execute 'noremap <expr> '.keys[1]." repmo#SelfKey('".keys[1]."', '".keys[0]."')|sunmap ".keys[1]
endfor
for keys in [ ['[s', ']s'], ['[S', ']S'] ]
execute 'noremap <expr> '.keys[0]." repmo#SelfKey('".keys[0]."', '".keys[1]."')|sunmap ".keys[0]
execute 'noremap <expr> '.keys[1]." repmo#SelfKey('".keys[1]."', '".keys[0]."')|sunmap ".keys[1]
endfor
for keys in [ ['[*', ']*'], ['[/', ']/'], ['[#', ']#'] ]
execute 'noremap <expr> '.keys[0]." repmo#SelfKey('".keys[0]."', '".keys[1]."')|sunmap ".keys[0]
execute 'noremap <expr> '.keys[1]." repmo#SelfKey('".keys[1]."', '".keys[0]."')|sunmap ".keys[1]
endfor
for keys in [ ['[z', ']z'], ['zj', 'zk'] ]
execute 'noremap <expr> '.keys[0]." repmo#SelfKey('".keys[0]."', '".keys[1]."')|sunmap ".keys[0]
execute 'noremap <expr> '.keys[1]." repmo#SelfKey('".keys[1]."', '".keys[0]."')|sunmap ".keys[1]
endfor
Selected third party
" Unimpaired
nmap <expr> ]q repmo#Key('<plug>unimpairedQNext', '<plug>unimpairedQPrevious')
nmap <expr> [q repmo#Key('<plug>unimpairedQPrevious', '<plug>unimpairedQNext')
nmap <expr> ]l repmo#Key('<plug>unimpairedLNext', '<plug>unimpairedLPrevious')
nmap <expr> [l repmo#Key('<plug>unimpairedLPrevious', '<plug>unimpairedLNext')
nmap <expr> ]n repmo#Key('<plug>unimpairedContextNext', '<plug>unimpairedContextPrevious')
nmap <expr> [n repmo#Key('<plug>unimpairedContextPrevious', '<plug>unimpairedContextNext')
omap <expr> ]n repmo#Key('<plug>unimpairedContextNext', '<plug>unimpairedContextPrevious')
omap <expr> [n repmo#Key('<plug>unimpairedContextPrevious', '<plug>unimpairedContextNext')
" Matchup
for keys in [ ['%', 'g%'], ['[%', ']%'] ]
execute 'map <expr> '.keys[0]." repmo#Key('<plug>(matchup-".keys[0].")', '<plug>(matchup-".keys[1].")')|sunmap ".keys[0]
execute 'map <expr> '.keys[1]." repmo#Key('<plug>(matchup-".keys[1].")', '<plug>(matchup-".keys[0].")')|sunmap ".keys[1]
endfor
" Vimtex
function! Repmo_vimtex()
map <expr><buffer> ]] repmo#Key('<plug>(vimtex-]])', '<plug>(vimtex-[[)')|sunmap <buffer> ]]
map <expr><buffer> [[ repmo#Key('<plug>(vimtex-[[)', '<plug>(vimtex-]])')|sunmap <buffer> [[
map <expr><buffer> ][ repmo#Key('<plug>(vimtex-][)', '<plug>(vimtex-[])')|sunmap <buffer> ][
map <expr><buffer> [] repmo#Key('<plug>(vimtex-[])', '<plug>(vimtex-][)')|sunmap <buffer> []
endfunction
augroup repmo
autocmd!
autocmd FileType tex :call Repmo_vimtex()
augroup END
Suggested setups
One could suggest following different setups:
- extend only
fFtT
to include counts in ;, when counts used for fFtT, e.g. 2fe - extend for other horizontal movements h,l; w,b; W,B; e,ge; E,gE (in particular useful for ge,gE)
- extend for two-letter movements, e.g. zj,zk; gj,gk
- extend for two-key movements, e.g. '{,}' (=Shift+[) or CTRL-E/Y
- extend for ]-movements, e.g.
]M
and[M
- apply for all builtin movements
- support for ft-defined movements such as [[,]] in python, [", ]" in vim/sql, ]-, [- in eiffel (use dedicated repo https://github.com/Houl/refrftsc-vim)
- support third party plugins such as unimpaired, vimtex, matchup, ...
Default setups seem useful, not sure yet how to present this to the user. And how to combine this with the <Plug>]]-motion
approach.
And maybe: some easy toggling during session (disabling should be as easy as enabling).
Maybe: detection of supported plugins during session (when everything is loaded), creating a config variable that can be put in the vimrc (something like that).
Suggestions?
For GitGutter users:
:nmap <expr> ]c repmo#Key('<Plug>GitGutterNextHunk', '<Plug>GitGutterPrevHunk')
:nmap <expr> [c repmo#Key('<Plug>GitGutterPrevHunk', '<Plug>GitGutterNextHunk')
I would present it as:
" Repeat the last [count]motion or the last zap-key:
:map <expr> ; repmo#LastKey(';')|sunmap ;
:map <expr> , repmo#LastRevKey(',')|sunmap ,
" include count in ; and , for fFtT which is not the case in default vim
for key in [ 'f', 'F', 't', 'T']
execute 'noremap <expr> '.key." repmo#ZapKey('".key."')|sunmap ".key
endfor
" nmap
for keys in [ ['<C-E>', '<C-Y>'], ['<C-B>', '<C-F>'], ['<C-D>', '<C-U>'] ]
execute 'nmap <expr> '.keys[0]." repmo#SelfKey('".keys[0]."', '".keys[1]."')"
execute 'nmap <expr> '.keys[1]." repmo#SelfKey('".keys[1]."', '".keys[0]."')"
endfor
" noremap and sunmap
for keys in [ ['h', 'l'], ['w', 'b'], ['W', 'B'], ['e', 'ge'], ['E', 'gE'],
\ ['j', 'k'], ['gj', 'gk'], ['-', '+'], ['(', ')'], ['{', '}'], ['[[', ']]'],
\ ['[]', ']['], ['[m', ']m'], ['[M', ']M'], ['[{', ']}'], ['[(', '])'],
\ ['[s', ']s'], ['[S', ']S'], ['[*', ']*'], ['[/', ']/'], ['[#', ']#'],
\ ['[z', ']z'], ['zj', 'zk'], ['zh', 'zl'] ]
execute 'noremap <expr> '.keys[0]." repmo#SelfKey('".keys[0]."', '".keys[1]."')|sunmap ".keys[0]
execute 'noremap <expr> '.keys[1]." repmo#SelfKey('".keys[1]."', '".keys[0]."')|sunmap ".keys[1]
endfor
Note I added zh
/ zl
for moving the viewport left/right.
Using https://github.com/Houl/repmohelper-vim:
" :PutRepmoSelfMap <C-E>|<C-Y> <C-B>|<C-F> <C-D>|<C-U>
noremap <expr> <C-E> repmo#SelfKey('<C-E>', '<C-Y>')|sunmap <C-E>
noremap <expr> <C-Y> repmo#SelfKey('<C-Y>', '<C-E>')|sunmap <C-Y>
noremap <expr> <C-B> repmo#SelfKey('<C-B>', '<C-F>')|sunmap <C-B>
noremap <expr> <C-F> repmo#SelfKey('<C-F>', '<C-B>')|sunmap <C-F>
noremap <expr> <C-D> repmo#SelfKey('<C-D>', '<C-U>')|sunmap <C-D>
noremap <expr> <C-U> repmo#SelfKey('<C-U>', '<C-D>')|sunmap <C-U>
" :PutRepmoSelfMap j|k gj|gk -|+
noremap <expr> j repmo#SelfKey('j', 'k')|sunmap j
noremap <expr> k repmo#SelfKey('k', 'j')|sunmap k
noremap <expr> gj repmo#SelfKey('gj', 'gk')|sunmap gj
noremap <expr> gk repmo#SelfKey('gk', 'gj')|sunmap gk
noremap <expr> - repmo#SelfKey('-', '+')|sunmap -
noremap <expr> + repmo#SelfKey('+', '-')|sunmap +
" ... and so on ...
" Matchup
" :PutRepmoMap <Plug>(matchup-<_>) %|g% [%|]%
map <expr> % repmo#Key('<Plug>(matchup-%)', '<Plug>(matchup-g%)')|sunmap %
map <expr> g% repmo#Key('<Plug>(matchup-g%)', '<Plug>(matchup-%)')|sunmap g%
map <expr> [% repmo#Key('<Plug>(matchup-[%)', '<Plug>(matchup-]%)')|sunmap [%
map <expr> ]% repmo#Key('<Plug>(matchup-]%)', '<Plug>(matchup-[%)')|sunmap ]%
" Vimtex
function! Repmo_vimtex()
" :PutRepmoMap <buffer> <Plug>(vimtex-<_>) ]]|[[ ][|[]
map <expr><buffer> ]] repmo#Key('<Plug>(vimtex-]])', '<Plug>(vimtex-[[)')|sunmap <buffer> ]]
map <expr><buffer> [[ repmo#Key('<Plug>(vimtex-[[)', '<Plug>(vimtex-]])')|sunmap <buffer> [[
map <expr><buffer> ][ repmo#Key('<Plug>(vimtex-][)', '<Plug>(vimtex-[])')|sunmap <buffer> ][
map <expr><buffer> [] repmo#Key('<Plug>(vimtex-[])', '<Plug>(vimtex-][)')|sunmap <buffer> []
endfunction
@kiryph I can't seem to get the unimpaired bindings working.
What do you get with :verbose map ]l
?
I get:
n ]l <Plug>unimpairedLNext
Last set from ~/.local/share/vim/bundle/vim-unimpaired/plugin/unimpaired.vim
Press ENTER or type command to continue
This is using:
nmap <expr> ]l repmo#Key('<plug>unimpairedLNext', '<plug>unimpairedLPrevious')
I had to place the unimpaired bindings using repmo into ~/.vim/after/plugin/repmo-unimpaired.vim
(filename is up to you except the file extension .vim
).
Otherwise vim-unimpaired itself has the last word. It looks like this is the case for you as well.
For comparison, I get:
n ]l repmo#Key('<Plug>unimpairedLNext', '<Plug>unimpairedLPrevious')
Last set from ~/.vim-configs/mwe-repmo-vim/after/plugin/repmo-unimpaired.vim line 5