Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I map multiple <leader> keys in vim?

Tags:

vim

I'd like to have a left and right hand leader key. If I want both the default \ and , to be my leaders I thought it would be as simple as adding nnoremap , \ or nnoremap , <leader> to my .vimrc. But apparently not. How do I do this?

like image 806
Dane O'Connor Avatar asked Dec 06 '11 04:12

Dane O'Connor


3 Answers

My <leader> is bound to , and this works for me:

:nmap \ ,

All of my leader mappings are now available using either \ or , as the leader. I think it's the nnoremap that's tripping you up.

like image 99
Greg Sexton Avatar answered Sep 22 '22 15:09

Greg Sexton


You can map one leader key to the other, as in the accepted answer, but if you're going to use <leader> in the first place, you should make the binding to <leader> itself. That way the binding will still work if you change (or remove) the first leader key.

map , <leader>

Note that this still doesn't quite work like a second leader. If the first leader is unset, the binding will still work, but Vim will also revert to using \ as a leader, since there is no longer an "official" leader (ie. valid value for the mapleader variable). (This wouldn't be a problem for the OP, but may be for others.)

like image 25
pyrocrasty Avatar answered Sep 21 '22 15:09

pyrocrasty


<leader> is convenient but you can create mappings like ,mm or \mm without using it. Just duplicate all your <leader>something and remap them with ' and \ directly:

nnoremap <leader>d "_d

would become

nnoremap ,d "_d
nnoremap \d "_d
like image 45
romainl Avatar answered Sep 21 '22 15:09

romainl