Search code examples
luaneovim

NeoVim cant find "keymap" (a nil value)


Im following "ThePrimeagen" tutorial on setting up NeoVim (https://www.youtube.com/watch?v=w7i4amO_zaE), but Im stuck at 3:13 where he ":so" (sources) the file.
In my case I get the error:
E5108: Error executing lua [string ":source (no file)]:2: attempt to index field 'keymap' (a nil value) stack traceback: [string ":source (no file)"]:2: in main chunk

I dont know much about lua, but what I understand is that it cant find "keymap", thats weird, everything works till now, I placed the nvim/lua folder on the right place, init.lua files work, only this remap that doesnt.
Any ideas on a solution?

the remap.lua file:

vim.g.mapleader = " "
vim.keymap.set("n", "<leader>pv", vim.cmd.Ex)

Solution

  • Wrong syntax. It should be vim.keymap.set("n", "<leader>pv", ":Ex<CR>"). vim.cmd("Ex") will open up netrw each time you source the file.