1

I want to map the <space> key to <leader> (which is currently the \ key here) in VIM 7.4.

I would also like to be able to use both the <space> and \ keys as leaders.

If possible, it would be great to see the / character appearing in the bottom right corner when I type it (instead of funky stuff like <20>), but I can live without it.

I've tried to

nmap <space> <bslash>

this works for simple <leader>keys commands, but <leader><leader>key commands (like the easymotion maps) don't work.

I also tried to

let mapleader = " "
nmap <bslash> <space>

but analogously to the problem above stated, the <bslash> key doesn't work anymore for <leader><leader>key commands.

I already tried a bunch of stuff in these related questions/wiki pages:

Xaphanius
  • 610
  • 2
  • 7
  • 19

1 Answers1

1

I can't see your .vimrc, so I can't guarantee this is the issue, but I would bet that the issue comes from using nnoremap. The following works for me:

let mapleader =" "
nmap <leader>i iHello World<esc>
nmap <bslash> <space>

I can use either <space>i or <bslash>i and both of them run the iHello World<esc> mapping. But this:

let mapleader =" "
nnoremap <leader>i iHello World<esc>
nnoremap <bslash> <space>

Does not work. <space>i runs the mapping, but <bslash>i does not, which is exactly what should be expected, since nnoremap is used to avoid nested/recursive mappings. So one possible solution would be to use nmap everywhere. I would definitely not recommend this, since you'll likely end up in a map loop. This solution should work better:

let mapleader =" "
nnoremap <leader>i iHello World<esc>
nmap <expr> <bslash> mapleader

Note that if you change the mapleader setting, this will break because, as :h mapleader says:

Note that the value of "mapleader" is used at the moment the mapping is
defined.  Changing "mapleader" after that has no effect for already defined
mappings.
DJMcMayhem
  • 7,285
  • 4
  • 41
  • 61
  • 1
    I see what you mean, but I am indeed using nmap. Using `nmap ` it works for single `` commands, but not for `` commands. I really don't know why. – Xaphanius Feb 20 '19 at 17:06