Vim's Leader Key (wtf is it?)

Sooner or later you’re going to hear mention of the leader key. In vimscript it looks like <Leader>. You can think of it as a trigger, or maybe a shortcut. macOS has the command key (⌘). Vim has the <Leader> key. You type it, and then usually two or three more characters to trigger some behavior like saying ⌘+o to open a file.

By default it is set to backslash \\ Lots of people remap it to something else that they find easier to type or remember. As long as you don’t overlap core letters, like the ones used to cut, copy & paste you’ll be fine.

Changing the Leader

If you feel you really need to remap it to something like, comma for example, you’d add this to your vimrc

let mapleader=","

I’ve come across many posts where people recommend mapping it to space. It’s a big easy to whack key and as far as I know doesn’t overlap with any internal functionality.

let mapleader = "\<Space>"

If you mapped it to something and have forgotten what you can either look in your .vimrc or tell vim to echo it out to you with echo mapleader

Common Leader Key behaviors

Just like most apps have a bunch of behaviors that can be triggered with ⌘+<something> Vim’s got a bunch of behaviors that can be triggered with <Leader>something. I don’t want to melt your brain, or mine, with a list that you’ll promptly forget. Plus, even if you have eidetic memory you still won’t know what the things mean without an explanation. Don’t worry. We’ll go over many of them in other posts.