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>
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.
In Lua, operand to concatenate 2 strings is ..
not +
as in Python.
Correct your code: function() io.popen("python3 ".. vim.fn.expand("%")) end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.