86

From http://items.sjbach.com/319/configuring-vim-right I got that you were supposed to be able to use Space as the mapleader in vim. I've tried but it does not seem to work. Anyone who have made it work?

Tried:

let mapleader = <space>
Sagar Jain
  • 6,261
  • 10
  • 40
  • 73
Marlun
  • 1,333
  • 2
  • 11
  • 14
  • 8
    Awesome! Just read the same blog post and found this after trying ... I found that in MacVim this didn't remove the mapping of "move one character forward" from the spacebar, so for others who find this from Google - add "nnoremap " before the "let mapleader..." this worked for me. – michiakig Oct 14 '10 at 04:13

4 Answers4

112

Try the following instead:

let mapleader=" "

And remember to write the following line before that, to make sure spacebar doesn't have any mapping beforehand:

nnoremap <SPACE> <Nop>
Imam Assidiqqi
  • 478
  • 4
  • 16
Zsolt Botykai
  • 46,263
  • 14
  • 81
  • 102
  • 21
    As spacemanaki comments in the question above `nnoremap ` was needed to get this working. – Sasha Nov 03 '11 at 02:16
  • 1
    @Sasha : really ? Could you explain why, and if it really is, then maybe you should edit the question. – greg0ire Dec 11 '13 at 11:00
  • 4
    Without sasha's mapping, pressing will not behave like other keys as mapleader. in normal mode is mapped to . Just press a couple of times in a row and you will see undesired behaviour, which can be fixed by `nnoremap `. – freeo May 23 '14 at 13:54
  • 3
    To add to this answer, note that the value of `mapleader` takes only affect mappings which happen after `mapleader` is set. See `:help leader`. – evnu Feb 28 '17 at 09:39
  • I had to save and close the rc file. I was using `:source %` but the space remap was not working. – Jonathan Morales Vélez Aug 22 '20 at 13:50
69

Mapleader is a Vim string variable. To use space as leader, you must escape the special character.

let mapleader = "\<Space>"

For more info see,

http://vimdoc.sourceforge.net/htmldoc/eval.html#expr-quote

EDIT:

This no longer works for me in my version of Vim. Even with the suggestion in the comments of unmapping the spacebar in normal mode by running nnoremap <SPACE> <Nop>.

I ending up going with the solution given in the answer below.

map <Space> <Leader>
jayWHY
  • 861
  • 7
  • 5
18

The above solutions are great, however, nothing shows up in the bottom right command corner. If you don't have any use for the \ key anyway, try using map <SPACE> <leader> and \ will show up in the command corner. That and you don't have to unmap space first, as suggested in the commends above.

thosehippos
  • 191
  • 1
  • 5
  • 3
    This breaks The NERD Commenter. And at least in Vim 8 and Neovim space shows up as `<20>` if `showcmd` is on, so I guess with new enough Vim this answer is obsolete. – user31389 Apr 12 '18 at 14:26
  • I just want to add here that this is also the best solution if you have already developed muscle memory for the default leader, but want to start using space instead for better efficiency. "\r" is still wired into my muscle memory for opening Nerd Tree and using cscope, so it is nice that it still works even when mapping space to leader (I don't feel a need to use Nerd Commenter, though). – DrEsperanto Aug 14 '20 at 17:44
0

nnoremap <space> <Nop>
nnoremap <nowait> <space> /

  • got extra '>' evey entry : left off "<"'s in definition
  • small delay each use : <nowait>
  • space may have previous bind : maped it to <Nop> first