Lua is throwing error when Vim keymap includes "\"

Viewed 474

I am recently migrating from vimscript to lua with Nvim. While converting the keymappings, I ran into a problem with the following keymap:

[ init.vim ]

tmap <leader>e <C-\><C-n>

[ init.lua ] ( error )

map('t','<leader>e','<C-\><C-n>')

Whenever I reload with above keymap, Nvim will throw the following error:

enter image description here

I'm assuming that "\" might be the problem. If so, how do I refactor the keymap properly for it to work? Any feedback will be greatly appreciated.

1 Answers

It is most likely as the \ is used to escape special characters in the string. Try putting

map('t','<leader>e','<C-\\><C-n>')

This way you are telling Lua that you want the backslash character and not some other special character.

Related