---
title: "Mapping Leaders in Vim"
url: "https://courses.osherove.com/courses/vim-hates-you/mapping-leaders-in-vim.md"
canonical: "https://courses.osherove.com/courses/vim-hates-you/mapping-leaders-in-vim/"
tags: []
author: "Roy Osherove"
description: "Lesson 21 of 26 in Vim Hates You (Go Faster), 3:57. Free video by Roy Osherove."
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Mapping Leaders in Vim

1. [Courses](https://courses.osherove.com/#courses)
2. [Vim Hates You](https://courses.osherove.com/courses/vim-hates-you/)
3. Go Faster

Lesson 21 of 26

Duration: 3:57 [Watch on YouTube](https://www.youtube.com/watch?v=4x2N5JNaIcI)

## In this lesson

Roy explains that the leader is a placeholder key, backslash by default, that many plugins use so that their mappings don't clash with existing key bindings, and that it can be changed with let mapleader. He maps the leader pressed twice to NERDTreeToggle and shows that, before the leader is set in the vimrc, the mapping works with two backslashes. He then sets the leader to comma in the vimrc, so two commas open NERDTree.

## Transcript

421 words

[\[00:08\]](https://www.youtube.com/watch?v=4x2N5JNaIcI&t=8s) Let's talk about leaders. Leaders in Vim are basically placeholders for any key that you'd like. And the default for a leader is the backslash. Now, you can change it. And many plugins use leader mappings so that they don't clash with existing key bindings that they currently have. If you want to change the leader, you just say let map leader be comma, which is what I usually use. So in Vim, what I would do, I can say let map leader equal

[\[00:38\]](https://www.youtube.com/watch?v=4x2N5JNaIcI&t=38s) Comma. And now what do I do? Well, I can set for example visibility of NERDTree just like I did previously. With let's say two map leaders. So I can say no let's say normal no re that's not recursive map

[\[01:09\]](https://www.youtube.com/watch?v=4x2N5JNaIcI&t=69s) Leader leader to NERDTreeToggle and of course cr for enter at the Now let's see if that works. Now let me type two commas. Let's do that again.

[\[01:42\]](https://www.youtube.com/watch?v=4x2N5JNaIcI&t=102s) Okay. So you can see that by using a map leader I can actually do a very very u powerful and generic thing and I can later change it. So if I don't feel comfortable with comma anymore I can change my leader to any other key that I'm comfortable with. So, I'll go to my vimrc and I'm going to say let's edit that. Let's edit the vimrc file and say here

[\[02:14\]](https://www.youtube.com/watch?v=4x2N5JNaIcI&t=134s) Under normal not recursive map leader will be mapped to NERDTreeToggle with cr. So now I'll have two ways to open NERDTree and two leaders. Now, I haven't mapped the leader yet in in the vimrc. So, I just want to show you the default leader in this case. So, I'm going to write

[\[02:47\]](https://www.youtube.com/watch?v=4x2N5JNaIcI&t=167s) I'm going to say source the vimrc. So, now if I press two leaders, I think because I mapped it in memory, this will still work. Let me close it down and do vim again. Now if I type two commas, nothing happens. But if I type two backslashes, I get NERDTreeToggle working. So let me go back and edit the vimrc.

[\[03:22\]](https://www.youtube.com/watch?v=4x2N5JNaIcI&t=202s) And this time I'm going to say shift g to go all the way to the end. And right before all these mappings, I'm going to say shift O and say let map leader equal comma because that's the way I like to work. Escape O just to have an empty line between there and right quit. If I now open vimrc again, two commas and I have exactly what I need.

[\[03:53\]](https://www.youtube.com/watch?v=4x2N5JNaIcI&t=233s) So that's how you use map leaders.

[Previous lesson Mapping keys to actions](https://courses.osherove.com/courses/vim-hates-you/mapping-keys-to-actions/) [Next lesson Edit and source your .Vimrc faster](https://courses.osherove.com/courses/vim-hates-you/edit-and-source-your-vimrc-faster/)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
