Houl / repmo-vim

Repeat motions [for which a count was given]
38 stars 5 forks source link

Extend README.md to add more possibilities to use this plugin #3

Open kiryph opened 6 years ago

kiryph commented 6 years ago

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:

1) extend only fFtT to include counts in ;, when counts used for fFtT, e.g. 2fe 2) extend for other horizontal movements h,l; w,b; W,B; e,ge; E,gE (in particular useful for ge,gE) 3) extend for two-letter movements, e.g. zj,zk; gj,gk 4) extend for two-key movements, e.g. '{,}' (=Shift+[) or CTRL-E/Y 5) extend for ]-movements, e.g. ]M and [M 6) apply for all builtin movements

Houl commented 6 years ago

For

  1. extend only fFtT to include counts in ;, when counts used for fFtT, e.g. 2fe

see #5

Houl commented 6 years ago

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?

HaleTom commented 6 years ago

For GitGutter users:

:nmap <expr> ]c repmo#Key('<Plug>GitGutterNextHunk', '<Plug>GitGutterPrevHunk')
:nmap <expr> [c repmo#Key('<Plug>GitGutterPrevHunk', '<Plug>GitGutterNextHunk')
HaleTom commented 6 years ago

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.

Houl commented 6 years ago

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
HaleTom commented 5 years ago

@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')
kiryph commented 5 years ago

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 
HaleTom commented 5 years ago

Thanks @kiryph for the reply!

It works fine with gitgutter, so I assume there's something that in unimparied that's... impaired.