How can I figure out which key is set as my <Leader>, and how do I remap it?
- 62,054
- 25
- 192
- 271
- 1,245
- 2
- 9
- 7
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.
- 62,054
- 25
- 192
- 271
- 3,566
- 3
- 20
- 27
You can display the current leader key like this :let mapleader
- 2,481
- 20
- 13
-
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. – Praxeolitic Feb 04 '15 at 09:45
-
4if you get
E121: Undefined variable: mapleader, that means it was not set, which will use the default, which is a backslash"\"– wisbucky Jun 26 '19 at 18:28
"\<Space>"? – thameera Feb 04 '15 at 09:52:help expr-stringfor examples.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:32maplocalleaderis also set to backslash by default. Maybe that's what was meant by "is the same asmapleader, but I wasn't sure at first. – Mars Jan 05 '18 at 04:11let mapleader = ","after the fact? I triedunlet mapleaderas well aslet 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