How can I figure out which key is set as my <Leader>
, and how do I remap it?
2 Answers
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
.
-
6
-
14The backslash is required because otherwise vim will recognize "<Space>" as a normal string and not the code for the space key. See
:help expr-string
for examples.– tokoyamiFeb 4, 2015 at 14:38 -
2Just 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. Feb 20, 2015 at 12:32 -
It appears that
maplocalleader
is also set to backslash by default. Maybe that's what was meant by "is the same asmapleader
, but I wasn't sure at first.– MarsJan 5, 2018 at 4:11 -
2How can I undo a
let mapleader = ","
after the fact? I triedunlet mapleader
as well aslet mapleader = "\"
but it doesn't work. I need this because I am using this bundle 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.– MichaelSep 1, 2019 at 17:48
You can display the current leader key like this :let mapleader
-
4
-
-
5Oh, got it. Just a note for others then, if you don't explicitly set the leader key then you get the error above. Feb 4, 2015 at 9:45
-
3if you get
E121: Undefined variable: mapleader
, that means it was not set, which will use the default, which is a backslash"\"
– wisbuckyJun 26, 2019 at 18:28