Home » Questions » Computers [ Ask a new question ]

Repeat not only the last change but the others as well in Vim

Repeat not only the last change but the others as well in Vim

How can I repeat not only the last used modification(.) but also more earlier ones?

Asked by: Guest | Views: 65
Total answers/comments: 2
Guest [Entry]

"To expand on @ldigas' comment about record and macros, here is a simple breakdown.

Press q to enter ""record"" mode.
Press what key you want to ""name"" the macro, I usually use w for one-time-use macros, but you can use any letter you want.
Perform the operations you want to repeat.
Press q to stop recording.

Once you have your macro, you can replay it by using @w (assuming you used w), and it will roll through the actions you recorded."
Guest [Entry]

"Again expanding on mapping your commands to be repeated:
When you know without visual feedback what you want to repeat, this [Ctrl-]Space mapping saves another few keystrokes:

"" map in Normal and Visual modes, but not Select mode (see :help mapmode-x
:command -nargs=* Nxmap nmap <args>| xmap <args>
com -nargs=* Nxnoremap nnoremap <args>| xnoremap <args>
com -nargs=* Nxunmap nunmap <args>| xunmap <args>

"" map <Space> to currently often-used operations (similar to space.vim)
"" quickly create custom mappings
"" Usage: <C-Space>YOURMAPPING<Enter> and then just <Space> for each repetition
"" (When you know without visual feedback what you want to repeat, this saves another few keystrokes.)
Nxmap <C-Space> :Nxmap <lt>Space>

"" make these commands repeatable by <Space> (similar to space.vim)
let space_repeats_nx = ['@@','@:']
for cmd in space_repeats_nx
exe 'Nxnoremap '.cmd.' :Nxnoremap <lt>Space> 'cmd.'<CR>'.cmd
endfor"