Plugin repmo-vim by Andy Wakula
The plugin #2174 listed on https://www.vim.org/scripts is, according to the description, outdated:
2016 Nov 22 started a new script at https://github.com/Houl/vim-repmo
The new plugin on github works for me when repeating, e.g. ]m
/[m
and ]M
/[M
with ;
and ,
. My minimal configuration looks like using vim8 packages (vim 8.1.560 on macOS 10.12):
~/.vim
❯ tree
.
├── pack
│ └── repeat-complicated-motions
│ └── start
│ └── repmo-vim
│ ├── README.markdown
│ └── autoload
│ └── repmo.vim
└── vimrc
5 directories, 3 files
" ~/.vim/vimrc
source $VIMRUNTIME/defaults.vim
map <expr> ; repmo#LastKey(';')|sunmap ;
map <expr> , repmo#LastRevKey(',')|sunmap ,
" Still repeat fFtT (now with counts):
noremap <expr> f repmo#ZapKey('f')|sunmap f
noremap <expr> F repmo#ZapKey('F')|sunmap F
noremap <expr> t repmo#ZapKey('t')|sunmap t
noremap <expr> T repmo#ZapKey('T')|sunmap T
" Now following can also be repeated with `;` and `,`:
for keys in [ ['[[', ']]'], ['[]', ']['], ['[m', ']m'], ['[M', ']M'], ['[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
Example java file:
public class Factorial
{
public static void main(String[] args)
{ final int NUM_FACTS = 100; // ; after [m
for(int i = 0; i < NUM_FACTS; i++)
System.out.println( i + "! is " + factorial(i));
} // , after ]M
public static int factorial(int n)
{ int result = 1; // [m
for(int i = 2; i <= n; i++)
result *= i; // CURSOR
return result;
} // ]M
}
// vim: ft=java
Also when I open a diff (e.g. with :Gdiff
from vim-fugitive), repeating ]c
and [c
are possible.
<Plug>
mappings of ftplugins
Another possible issue with [m
, [M
is that you have to remap them for filetypes with overwrites and you want to use the overwrites. Examples are python, vimscript, and ruby.
Unfortunately, many ftplugins do not provide them as <plug>
mappings which repmo-vim needs.
The ftplugin vim-pythonsense provides them as <plug>
mappings:
" ~/.vim/after/ftplugin/python.vim
map <expr><buffer> ]] repmo#Key('<plug>(PythonsenseStartOfNextPythonClass)', '<plug>(PythonsenseStartOfPythonClass)')|sunmap <buffer> ]]
map <expr><buffer> [[ repmo#Key('<plug>(PythonsenseStartOfPythonClass)', '<plug>(PythonsenseStartOfNextPythonClass)')|sunmap <buffer> [[
map <expr><buffer> ][ repmo#Key('<plug>(PythonsenseEndOfPythonClass)', '<plug>(PythonsenseEndOfPreviousPythonClass)')|sunmap <buffer> ][
map <expr><buffer> [] repmo#Key('<plug>(PythonsenseEndOfPreviousPythonClass)', '<plug>(PythonsenseEndOfPythonClass)')|sunmap <buffer> []
map <expr><buffer> ]m repmo#Key('<plug>(PythonsenseStartOfNextPythonFunction)', '<plug>(PythonsenseStartOfPythonFunction)')|sunmap <buffer> ]m
map <expr><buffer> [m repmo#Key('<plug>(PythonsenseStartOfPythonFunction)', '<plug>(PythonsenseStartOfNextPythonFunction)')|sunmap <buffer> [m
map <expr><buffer> ]M repmo#Key('<plug>(PythonsenseEndOfPythonFunction)', '<plug>(PythonsenseEndOfPreviousPythonFunction)')|sunmap <buffer> ]M
map <expr><buffer> [M repmo#Key('<plug>(PythonsenseEndOfPreviousPythonFunction)', '<plug>(PythonsenseEndOfPythonFunction)')|sunmap <buffer> [M
Also the ftplugin vimtex provides them as <plug>
mappings and the configuration becomes:
" ~/.vim/after/ftplugin/tex.vim
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> []
map <expr><buffer> ]m repmo#Key('<plug>(vimtex-]m)', '<plug>(vimtex-[m)')|sunmap <buffer> ]m
map <expr><buffer> [m repmo#Key('<plug>(vimtex-[m)', '<plug>(vimtex-]m)')|sunmap <buffer> [m
map <expr><buffer> ]M repmo#Key('<plug>(vimtex-]M)', '<plug>(vimtex-[M)')|sunmap <buffer> ]M
map <expr><buffer> [M repmo#Key('<plug>(vimtex-[M)', '<plug>(vimtex-]M)')|sunmap <buffer> [M
If you want to use the ones in $VIMRUNTIME/ftplugin/{
python
,
ruby
,
vim
}.vim
you have to rewrite them as <plug>
mappings and put them into repmo#Key
.
What file types are you interested in?