繁体   English   中英

如何在 lua nvim 配置中执行 map shell 命令?

[英]How to map a shell command in the lua nvim config?

如何在 lua nvim 配置中执行 map shell 命令?

maps.n["<F4>"] = { function() io.popen("python3 " + vim.fn.expand("%")) end, desc = "Run current Python file"}

错误:

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>

也许这不是您正在寻找的东西,但我为此使用了toggleterm 之类的插件。 您可以设置键盘映射以运行您想要的任何 shell 命令或程序,也可以让它显示在浮动或非浮动 window 中。

至于只是在没有任何插件的情况下映射它并执行命令,我并不完全确定。

在 Lua 中,连接 2 个字符串的操作数是..而不是 Python 中的+

更正您的代码: function() io.popen("python3 ".. vim.fn.expand("%")) end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM