![](/img/trans.png)
[英]Lua Nvim —— Error loading lua [string ":lua"]:5: '}' expected (to close '{' at line 3) near '['
[英]Error loading lua [string: "lua"]:1: function arguments expected near ','
我在autoload\utils.lua
中有一個 function,它根據方向更改緩沖區:
local function GoToBuffer(count, direction)
if count == 0 then
if direction == "forward" then
vim.api.nvim_command("bnext")
elseif direction == "backward" then
vim.api.nvim_command("bprevious")
else
vim.api.nvim_err_writeln("Bad argument " .. direction)
end
return
end
if vim.tbl_index(GetBufNums(), count) == -1 then
vim.fn.nvim_notify(string.format("Invalid bufnr: %d", count), 4, { title = "nvim-config" })
return
end
if direction == "forward" then
vim.api.nvim_command(string.format("buffer%d", count))
end
end
local function GetBufNums()
local buf_list = {}
for _, buf in ipairs(vim.api.nvim_get_buf_info({ buflisted = 1 })) do
buf_list[#buf_list + 1] = buf.bufnr
end
return buf_list
end
我使用 vim.keymap.set 將一個鍵映射到這個vim.keymap.set
:
local utils = require('autoload.utils')
keymap.set("n", "gb", '<cmd>:lua utils.GoToBuffer(v:count, "forward")<cr>', {})
keymap.set("n", "gB", '<cmd>:lua utils.GoToBuffer(v:count, "backward")<cr>', {})
當我使用鍵綁定時,出現此錯誤:
Error loading lua [string: "lua"]:1: function arguments expected near ','
代碼不起作用的原因是因為v:count
是您在 vimscript 中訪問變量的方式,而在 lua 中它vim.v.count
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.