[vim] a concrete repeat.vim example
In vim you have a custom mapping that consists of a series of commands. You would like to repeat it with the “.” command but it only repeats the last part of the series of commands, not the whole.
Tim Pope has a plugin for this called repeat.vim . However, he doesn’t give a concrete example in the README so it’s very hard to figure out how it works.
Let’s see the following mapping that surrounds a word with apostrophes:
nnoremap <Leader>' viw<esc>a'<esc>hbi'<esc>lel
Usage: put the cursor on a word and press
<Leader>' to surround it.
If you try to repeat it with “.”, it will only repeat the insertion of the second apostrophe.
How to make the whole mapping repeatable:
nnoremap <silent> <Plug>SurroundWordWithApostrophe viw<esc>a'<esc>hbi'<esc>lel \ :call repeat#set("\<Plug>SurroundWordWithApostrophe", v:count)<cr> nmap <Leader>' <Plug>SurroundWordWithApostrophe