First, open your
.vimrc file. This is typically found in your home directory:
Now use the following to set the leader key.
let mapleader = ","
In the above example, I mapped the leader to
,. This is much easier to access than
\, but you can map the leader to whatever key you'd like!
For this change to take effect, you'll have to re-launch Vim.
Even though it isn't the main purpose of this guide, I figured it would be useful to provide an example shortcut using the leader key.
One of the commands I use frequently is
:buffdo e!. Sometimes the files in my current project have been changed by another program (like changing branches in git). This command force reloads the files in each of my buffers.
As you can imagine, typing this is a pain. Typing
,e is much easier. Add the following to your
.vimrc file to create shortcuts like this one:
map <leader>e :bufdo e!<CR>
,e is typed, it will be as if I typed
:buffdo e!<CR> (