Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Perfect variant would be choose them by Ctrl+N and Ctrl+P.

share|improve this question
up vote 4 down vote accepted

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

  1. Press q to enter "record" mode.
  2. 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.
  3. Perform the operations you want to repeat.
  4. 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.

share|improve this answer
+1 I also like @@ for repeat the last run macro. – tidbeck Feb 25 '12 at 10:24

I wouldn't recommend remapping C-N and C-P, since they are autocompletion mappings, and often plugins use them. As a matter of fact, I wouldn't recomment remapping any of vim's default mappings. But anyways, that's up to you.

As far as repeating goes, the dot (.) will repeat the things you did on your last row. If you are having some problems with repeat command with some plugins, try the repeat.vim plugin.

If you wish to have some opeations which you use often at your disposal, try recording it in a register and then playing it (":help record"), or making it a function and then calling the function (if you do wish, I guess the call to function could be made as C-N or C-P ...)

share|improve this answer
qq - macros ftw =) – akira Oct 4 '09 at 9:10
q[a-zA-Z] actually :) – Rook Oct 4 '09 at 11:58
(good) plugins should not be upset by custom mappings, since they can circumvent them with :noremap – accolade Feb 25 '12 at 0:23

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
share|improve this answer

I made the RepeatLast.vim plugin to provide this functionality with 5\.

It works by enabling macro recording all the time. For that reason I don't really recommend it! But it was the only way I found possible to perform multiple repeats retrospectively. It would be great if Vim could provide access to recent keystrokes internally.

Remembering to hit q before performing something you will want to repeat is preferable.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .