36

I see <Leader> quite often in other people's vimrc files. Like this one.

What is it? What does it do?

  • 1
    possible duplicate of How can I find out what <Leader> is set to? – akshay Feb 16 '15 at 4:17
  • 9
    Akshay: Not a duplicate, that wants to check the value of <leader>, this one wants to know what <leader> means. So that that value can be interpreted. It is the difference between asking "In newton motion what is v?" and "Given an apple falled from a 10m high tree, what is v when it hits the ground?' – Lyndon White Feb 16 '15 at 4:26
  • 3
    So, there is no difference between <Leader> and <leader>, right? – Nikos Alexandris May 3 '15 at 11:31
25

Vim is full of various commands, which are assigned to almost all keys on the keyboard. But this causes a problem: Which commands can we use for our own commands, without interfering with existing ones? And at this moment, the <Leader> key comes into play. Think about <Leader>-key like a namespace for any user-defined commands. You can assign any command to a mapping with a leading <Leader> and you can be fully confident that your mapping won't break anything.

Default key for <Leader> is backslash.

15

To quote :help <Leader>:

To define a mapping which uses the "mapleader" variable, the special string "<Leader>" can be used. It is replaced with the string value of "mapleader". If "mapleader" is not set or empty, a backslash is used instead. Example:

   :map <Leader>A  oanother line<Esc>  

Works like:

   :map \A  oanother line<Esc>  

But after:

   :let mapleader = ","  

It works like:

   :map ,A  oanother line<Esc>

In other words, it lets the first key of mappings (specified in terms of <Leader>) be user defined.

  • 8
    I believe that the rationale behind the <Leader> is that it provides you with a "clean" way to provide custom shortcuts, without overriding existing Vim shortcuts. – Martin Tournoij Feb 16 '15 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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