Search code examples
vimmacvim

What is the <leader> in a .vimrc file?


I see <leader> in many .vimrc files, and I am wondering what does it mean?

What is it used for?

Just a general overview of the purpose and usage would be great.


Solution

  • The <Leader> key is mapped to \ by default. So if you have a map of <Leader>t, you can execute it by default with \+t. For more detail or re-assigning it using the mapleader variable, see

    :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>
    
    Note that the value of "mapleader" is used at the moment the mapping is
    defined.  Changing "mapleader" after that has no effect for already defined
    mappings.