How do I use `<space>` as the leader in visual mode?

I have my leader set to space via

vim.g.mapleader = " "
vim.g.maplocalleader = " "

but it does not work in visual mode. It seems to be advancing one character instead which is totally useless.

Could anyone let me know how to use space as leader in visual mode as if it were normal mode?

Thanks!

Try also adding
vim.api.nvim_set_keymap('', '<Space>', '<Nop>', { noremap = true, silent = true }) to unmap space.

1 Like

@mjlbach thereā€™s nvim_del_keymap to remove keymaps . Also this might not becasue of is mapped as going one step forword is spaces default behaviour. And if it was mapped it should still wait till ā€˜updatetimeā€™.

Rather unbelievably neither of these seems to do it. In facto nvim_del_keymap crashes if I run it before nvim_set_keymap because it seems nvim really considered it not mapped.

So I guess this is ā€œhard-codedā€ somewhere much deeperā€¦

Itā€™s not hard coded . I canā€™t reproduce it.

Try writting these to test_init.vim

let mapleader = " "
nmap <leader>t :<C-u>echo "Normal map"<cr>
vmap <leader>v :<C-u>echo "Visual map"<cr>

Open nvim with nvim -u test_init.vim
Then tryout t in normal and v in visual mode.

For me they work correctly. Probably a config issue on your end .

Yeah, youā€™re right it works.

Ok, I seem to have a bigger problem with plugins overriding my keymaps somewhere. Iā€™ve tried a couple of other re-bindings that are also not working.

I seem to have an analogous problem with just about every character except for alphanumerics and the F keys.

Is there any way of figuring out what is screwing up my bindings so I can disable it?

If you know which key to look for (assume itā€™s space).

You can try

:verbose vmap <space>

Itā€™ll tell you which file and line keymap was set from .

Though if itā€™s done by lua plugin verbose doesnā€™t work there yet . Itā€™s WIP feat(lua): Fix :verbose for lua config by shadmansaleh Ā· Pull Request #15079 Ā· neovim/neovim Ā· GitHub . You can try that branch If you hit ā€˜set from Luaā€™

Or you could just binary search your config.

Pardon me for asking a newbie question. Whatā€™s the difference between mapleader and maplocalleader. Is there any functional difference. I have been only using the mapleader option.

If youā€™re new in (neo)vim land :help is your friend.
You can see what it is with :h maplocalleader

Basically itā€™s for buffer local mappings . I donā€™t use it either . Never really found a use for it yet :smiley:

Ok, this was a bit of a saga. Ultimately, if I add bindings to <space> in visual it will work it just still increments characters if you spam it. Still donā€™t understand what the deal is but itā€™s working for what I had originally intended, so I canā€™t be bothered pursuing it further.

Something else I was frustrated with was that I was having similar problems with <bs>. TL;DR some weird crap seemed to be going on with my plugins regarding <bs>, in particular some unmodifiable bindings from UltiSnips, so really <bs> was the worst case scenario. I really should open an issue in ultisnips about it, but I donā€™t really understand why I canā€™t just rebind the thing normally so might not be worth doing. Otherwise, I gave up on <bs>.

vim.api.nvim_set_keymap('', '<Space>', '<Nop>', { noremap = true, silent = true })

I found this to be a requirement on Windows