Vim 101: What is the Leader Key?

Alex R. Young
Aug 19, 2012 · 1 min read

You’re happily using Vim, slowly mastering file navigation, split windows and tabs, search and replace, and then you discover a hot new .vimrc on Hacker News that includes lots of commands like this:

noremap <Leader>W :w !sudo tee % > /dev/null

What the devil is <Leader>? Well, in this example it simply means typing \W (backslash then w) in Normal mode will save the current file using the sudo command. Does that mean <Leader> means backslash? Well, not quite. The <Leader> key is a reference to a specific key defined by the mapleader variable. A lot of people change to comma because they find it easier to type:

let mapleader=","

The mapleader variable is easy to change, and if you always remember to map keys with <Leader> then you'll avoid confusing your own customisation with Vim's default keyboard shortcuts.

The beauty of the <Leader> key is it effectively gives us a namespace for customised keyboard shortcuts. You don't need to worry about treading on Vim's toes when you set a keyboard shortcut using <Leader>.

Vim waits for 1000 milliseconds after the <Leader> key has been pressed, so if you take too long to press the next key in the sequence it won't be matched. This timeout can be changed by using :set timeoutlen to set specific value.


A blog about Vim

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store