簡體   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