vim 基础知识

leader

https://vi.stackexchange.com/questions/836/what-is-leader

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.

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.

posted @ 2021-03-13 20:57  fndefbwefsowpvqfx  阅读(61)  评论(0编辑  收藏  举报