I am migrating from vimscript to lua for my keybindings and I have remapped the leader key as space:

vim.g.mapleader = " "

It works fine with all my key bindings. Except in visual mode.

When I am in visual mode, the leader is automatically rejected.

I thought .g. make it global and for all modes? if not, how can I make this usable in all modes?


this is not a lua issue. I changed it back to vimscript and the issue is still there. the main change I made in the last 24 hours was updating to nvim 0.7

  • Does it work if you set it to "<Space>" instead?
    – filbranden
    Apr 27, 2022 at 7:20
  • 1
    I don't think this is an issue in regular vim: :let g:mapleader = " " and :xnoremap <leader> :<C-u>echo "hello"<CR> works fine
    – D. Ben Knoble
    Apr 27, 2022 at 13:49
  • 1
    Looks fine both in 0.7 and 0.8. Please, provide minimal reproducible config.
    – Matt
    Apr 27, 2022 at 15:12

1 Answer 1


For anyone migrating from vimscript to lua, make sure you are mindful of the vim mode that you set inside the vim.keymap.set function.

The vim.keymap.set function has 4 arguments. The first argument is a character that represents a mode. EG - "n" = normal mode.

Im my key bindings, I had set all keys to "n". hence, the leader key was deactivated for all other modes (I do not know why!) Like this for example:

vim.keymap.set("n","<leader>\",":make") <-- executes make in normal mode only.

To solve this, I simply added a new keybinding for all modes:

If you use vim.keymap.set with no mode (a blank string) your key will be registered for all modes.

("","<leader>\",":make") <--- :make in all modes

And now leader works. Again, I find this strange.

  • Huh? Not sure I understand what adding a keymap with no mode has to do with it... Can you be more specific about what was it that solved your problem?
    – filbranden
    Apr 27, 2022 at 16:10
  • And, by the way, thanks for coming back and posting an answer, that's much appreciated! Just wanted to make sure you can clarify what was it that solved it for you, so that others hitting this issue might be able to use the same solution that worked for you.
    – filbranden
    Apr 27, 2022 at 16:11
  • 1
    Apologies, I have provided more context.
    – Vinn
    Apr 27, 2022 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.