The “Leader key” is a way of extending the power of VIM's shortcuts by using sequences of keys to perform a command. The default leader key is backslash.
To change the leader key to the comma , add let mapleader = “,” to your vimrc (to use the space key add let mapleader = “ “). Reload vim and test your new <leader> key. The leader key can be whatever key you choose.
Vim has a second "leader" key called "local leader". This is meant to be a prefix for mappings that only take effect for certain types of files, like Python files or HTML files.
The <CR> in vim mappings is the carriage return usually the Enter on your keyboard.
To see the current value currently defined for <leader>
, use:
:let mapleader
Producing output like:
mapleader ,
It may be undefined if not previously set, defaulting instead to a backslash \
By default mapleader
is not set, and special string "<Leader>"
means \
.
If you do:
:echo mapleader
you will get
Undefined variable: mapleader
Invalid expression: mapleader
If you want to set special string "<Leader>"
to a different key, say ","
, which is recommended by many, do:
:let mapleader=","
Then
:echo mapleader
,
Fortunately, map
expands <key_name>
values in both the LHS and RHS. You can exploit this to see the value of <Leader>
even if it is the default value.
:nmap temp :echo('your leader is "<Leader>"')<Esc>| execute 'normal temp'| nunmap temp
Note that if you put this in your .vim/vimrc
it will pause with "Press ENTER or type command to continue". Please comment if you know how to fix this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With