Mapping <leader> in vim.api.nvim_set_keymap() does not work

Viewed 2135

I have my leader key mapped as

nnoremap <SPACE> <Nop>
let mapleader = " "

Setting up lsp keybindings from lspconfig, there are keybinds defined like

vim.api.nvim_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)

Since space is my leader, this doesn't work, so I rewrote it as

vim.api.nvim_set_keymap('n', '<leader>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)

However, pressing e does nothing, the outcome is the same as <space>e:

The leader is recognized but when e is pressed, it simply moves the cursor forward to the end of the word which is the default binding for e. binding other keys works fine, only the leader key seems to have this problem.

1 Answers

Nvim leader was mapped after the above bind. I have them on different files sourced into init.vim. The one with the lsp configuration was being sourced before the one with the other mappings. Sourcing the lspconfig file after the mappings file fixed the issue.

Related