106

How can I figure out which key is set as my <Leader>, and how do I remap it?

Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
krampstudio
  • 1,245
  • 2
  • 9
  • 7

2 Answers2

106

By default your <leader> is \, backslash. You can check it with:

:echo mapleader

If this gives you an E121: Undefined variable: mapleader, it means it's set to the default of \. If it gives you something else, then it's that :-)

You can easily remap it. I mapped it to the space-bar:

:let mapleader = "\<Space>"

Note that the value of mapleader is used at the moment the mapping is defined. So this example:

let mapleader = ","
nnoremap <Leader>a :echo "Hey there ,"<CR>

let mapleader = "\<Space>"
nnoremap <Leader>a :echo "Hey there space"<CR>

Will produce two mappings: ,a and <Space>a.

This means that the current value of mapleader is not necessarily the value that was used to define your mappings!

In addition, there's the maplocalleader, which is the same as mapleader, except that it's used by <LocalLeader> and that it's local to the current buffer.

More information about <Leader> can be found in Vim's help with :help mapleader.

Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
OrangeTux
  • 3,566
  • 3
  • 20
  • 27
  • 7
    Why do we need a backslash in "\<Space>"? – thameera Feb 04 '15 at 09:52
  • 16
    The backslash is required because otherwise vim will recognize "" as a normal string and not the code for the space key. See :help expr-string for examples. – tokoyami Feb 04 '15 at 14:38
  • 2
    Just a note: e.g. let mapleader = ' ' also works for setting <Leader> to space. If there are any possible side-effects by using this syntax, feel free to mention them. – Daniel Andersson Feb 20 '15 at 12:32
  • It appears that maplocalleader is also set to backslash by default. Maybe that's what was meant by "is the same as mapleader, but I wasn't sure at first. – Mars Jan 05 '18 at 04:11
  • 2
    How can I undo a let mapleader = "," after the fact? I tried unlet mapleader as well as let mapleader = "\" but it doesn't work. I need this because I am using this bundle https://github.com/amix/vimrc where it suggests to have my own separate configuration file. The bundle maps leader to the comma so I want to undo this in my separate config file. – Michael Sep 01 '19 at 17:48
  • I also need to unmap my leader. I accidentally saved it to let mapleader = ";" and now I don't want that mapping anymore – Ethan Fischer Jun 16 '20 at 17:04
11

You can display the current leader key like this :let mapleader

craigp
  • 2,481
  • 20
  • 13