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.

@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>.