Currently I tend to use macros and have not learned how to use the leader key which seems to provide much the same functionality.

Aside from it being easier to type , than @ what is the gestalt of using a leader key as opposed to a macro?

  • 2
    A macro is something you record and replay. The leader key is a sort of shift, it allows you to define new key mappings, even though most easily accessible keys on the keyboard are already taken. Basically, you're comparing apples with orange juice. Jul 7, 2016 at 16:07
  • @SatoKatsura I understand what they do, I just don't understand on practical basis what the difference is between them. Why not just use macros for everything? Why ever use a leader key, when I can do the same thing with a macro? Jul 7, 2016 at 16:08
  • 1
    From my vimrc: nmap <Leader>[ <Plug>yankstack_substitute_older_paste. How would you write this as a macro? Jul 7, 2016 at 16:14

3 Answers 3


I can see some confusion if you have been reading the help docs because they use some similar names even though these two things are pretty different.

The @ command will "play back" the contents of the register. Usually, macros are recorded into the registers with the q command. You can also set the registers by yanking into them or through vimscript. You can view :h @ for more info on how vim macros work.

The leader is designed to make managing your keybindings easier. For example, in my vimrc I have a keybinding to make quitting faster. nnoremap <leader>q :q<cr>. If I set my leader to , the command to quit would be ,q. If I set the leader to space, the command will be q. When you have a lot of keybindings, it can be convenient to have one "prefix" that you can type to use them all, to minimize the collisions with the native keybindings. :h leader will give you more information about this.

  • 1
    ...or you could just create the macro :q<CR> and assign it to Q so you type @q to do the same thing. I am still not seeing the difference. Jul 7, 2016 at 16:23
  • 2
    There are only 26 registers (ignoring all the special ones). I have many more than 26 keybindings. That's one problem. Another problem: what if I want to yank something into the q register to paste somewhere else? the minute I run "qyy, my quit macro is gone. Keybindings don't have this problem. Jul 7, 2016 at 16:25
  • 2
    Okay, from what you are saying macros are more for limited temporary functionality and key bindings for a wider range of long-lasting behavior. Is that the idea? Jul 7, 2016 at 16:27
  • Yes, exactly! :) Jul 7, 2016 at 16:28
  • 1
    @AaronMcMillin I don't use any insert mode mappings, I prefer to do things from normal mode. it is a pain in command mode when I have to type spaces, so I have <space><space> mapped to <space> just to be able to quickly enter a space :d Jul 7, 2016 at 21:44
  1. A macro is a sequence of keystrokes. Whether they are recorded or not, whether they are stored in a register or not is completely irrelevant.

    Macros can be recorded in an arbitrary register with :help q:


    and played back with :help @:


    Macros can be saved into an arbitrary register via :help y or via vimscript:

    :let @a = 'd2w'<CR>

    and used the same way:


    Macros can also be saved in a variable:

    :let foo = 'd2w'<CR>

    and used in a slightly different way:


    Macros can also be typed verbatim in the command-line, to be executed with :help :normal:

    :normal! d2w<CR>

    Macros can also be saved for later in the form of a mapping:

    :nnoremap <key> d2w

    and used by pressing <key>.

    In all the examples above, d2w is your macro. All the rest is more or less orthogonal to that macro.

  2. The <leader> key is not a special key at all.

  3. What you are trying to compare are two ways to play back macros, not… macros and something else.

    If you are more comfortable with registers, use registers along with any of the register-related methods above.

    If you are more comfortable with mappings, use mappings.

    If you are just starting with Vim, try both and decide for yourself.

Note: The best Vim video ever happens to revolve largely around macros.

  • I know this is an old answer, but I was curious on that best video ever link, since the blog is down and used to be on vimeo, is it this? youtu.be/JJle8L8FRy0
    – chriz
    Jul 19, 2020 at 14:29
  • 1
    @chriz, No, that's not the one. Here is a low-res version of the video I mentioned in my answer.
    – romainl
    Jul 20, 2020 at 16:14
  • hey @romainl 👋 Thanks! Fancy seeing you here, been bumping to you a lot in r/vim. I love macros! I sometimes fallback to macros if the regex becomes too complicated. What's crazy is macros can be applied to multiple files, so (:argdo, :cdo, and family) works.
    – chriz
    Jul 22, 2020 at 0:05
  • 1
    Hi @chriz, macros are indeed a powerful feature. FWIW, many editors have features similar to Vim's "recording" but macros go way beyond recording, which makes them usable in many contexts where recording wouldn't be the most appropriate option. Crazy indeed.
    – romainl
    Jul 23, 2020 at 8:37
  • yet another question, What if the macro you've recorded (and that works just fine executing through @) has a mix of normal and ex modes? some of my macros (which I've stored in my vimrc with let @m="...") will change buffers and use <C-R> to get to register values in Ex and insert mode. This apparently doesn't like to work in combination wtih :nnoremap <key> <cmd>
    – g19fanatic
    Aug 13, 2021 at 16:58

the leader key which seems to provide much the same functionality


A macro is the recording of a succession of keystrokes, that you can replay.

The leader key is a special key that you can use in your mapping with <leader> and change only once in your configuration file.

You may want to use a macro when having a repetitive task that you can repeat easily with a succession of keystrokes.

You may want to use the leader key when a mapping you are defining needs not to override an existing mapping or when you want to put the mapping in your "personal mapping".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.