Skip to main content
Home

Vim leader key

Disclaimer: This is by no means an introduction to what the leader key in vim is. There are a lot more exhaustive resources out on the internet for that. It's more of a why and a story around how I use it everyday in my workflow.

In vim contexts, it's known as a fact that leader key is used as a prefix/namespace to the key mappings that are used very often. This achieves two things at once:

  1. Avoids key clashes with vim's native mappings
  2. Allows you to create very short mappings to, potentially, very complex actions

You can set the leader like this, which will make it the comma:

let mapleader=","

I've used this setup for quite some time, but then I started to hate it for one reason: it hides away the vim's core function for comma -- to actually jump back on to previous character occurence on the current line. I just love using this keystroke.

asciicast

I cannot compromise on it.

What I like doing now, instead, is to set the leader key to the space bar. This gives the opportunity of using a key with a lot of real estate space on it, which makes it easily reachable with both of my thumbs, shall I need it.

The config I actually use:

let mapleader=" "

This makes up for a nice combo of mappings:

Hopefully this will make a brief overview of how I use the leader key and maybe I'll come up with describing more useful mappings with it.

Profile picture

Andrei Glingeanu's notes and thoughts. You should follow him on Twitter, Instagram or contact via email. The stuff he loves to read can be found here on this site or on goodreads. Wanna vent or buy me a coffee?