The leader key

You've probably already encountered a key referred to as the leader key. The leader key is essentially a namespace for user or plugin defined shortcuts. Within a second of pressing the leader key, any key that's pressed will be in from that namespace.

The default leader key is a backslash , but it's not the most comfortable binding. There are a few alternative keys that are popular in the community, with the comma (,) being the most popular. To rebind the leader key, set the following in your .vimrc file:

" Map the leader key to a comma.
let mapleader = ','

You'll want to define your leader key closer to the top of .vimrc, as the newly defined leader key will only apply to mappings defined after its definition.

When you rebind a key, it's default functionality is overwritten. For example, comma , this is used to replay the last tfT, or F movement commands, in the opposite direction.

My personal favorite is to use the spacebar as a leader key. It's a big key, which doesn't have any real use in normal mode (it mimics right arrow key functionality):

" Map the leader key to a spacebar.
let mapleader = "<space>"
The escape character  is needed before space since mapleader doesn't expect special characters (like space). Double quotes (") are also necessary for the escape to work, since single quotes (') only allow literal strings.

You can use leader in your .vimrc mappings like this:

" Save a file with leader-w.
noremap <leader>w :w<cr>

More often than not, you will use a leader key to map plugin functionality in a way that's easy for you to memorize, as in the following example:

 noremap <leader>n :NERDTreeToggle<cr>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.102.239