Reputation: 177
How to map a shell command in the lua nvim config?
maps.n["<F4>"] = { function() io.popen("python3 " + vim.fn.expand("%")) end, desc = "Run current Python file"}
Error:
E5108: Error executing lua: /home/kobe/.config/nvim/lua/core/mappings.lua:19: attempt to perform arithmetic on a string value
stack traceback:
/home/kobe/.config/nvim/lua/core/mappings.lua:19: in function </home/kobe/.config/nvim/lua/core/mappings.lua:19>
Upvotes: 1
Views: 5720
Reputation: 2342
In Lua, operand to concatenate 2 strings is ..
not +
as in Python.
Correct your code : function() io.popen("python3 " .. vim.fn.expand("%")) end
Upvotes: 2
Reputation: 11
Maybe this isn't exactly what you're looking for, but I use plugins like toggleterm for this. You can setup keymappings to run whatever shell command or program you want, and also have it show up in a floating or none-floating window, too.
As for just mapping it without any plugins and having the command be executing, I'm not entirely sure.
Upvotes: 1