我想把一些旧的病毒脚本迁移到lua。我有一堆“散文”的设置,现在在. .config/nvim/plugin/functions.lua中有这些设置:
function prose()
vim.o.fdo:append('search')
vim.bo.virtualedit = block
-- more commands
end然后在prose.lua中:
local textedit = vim.api.nvim_create_augroup('textedit', {clear = true})
vim.api.nvim_create_autocmd({"BufEnter", "BufNew"}, {
group = "textedit",
pattern = {"*.adoc", "*.md", "*.tex"},
callback = "prose",
})
vim.api.nvim_create_user_command(
'Prose',
"call prose()",
{nargs = 0, desc = 'Apply prose settings'}
)````
But either the autocommand on opening an .adoc file or running :Prose on the command line will return:
````E117: Unknown function: prose````我怎样才能使我的“散文”功能可用?
发布于 2022-08-28 23:05:22
首先,您的functions.lua文件必须位于.config/nvim/lua/目录中。
对于自动命令,修改回调以要求functions.lua和函数prose
callback = require('functions').prose()对于您的用户命令:
vim.api.nvim_create_user_command('Prose', function()
require('functions').prose()
end,
{nargs = 0, desc = 'Apply prose settings'}
) 发布于 2022-10-20 16:15:39
对Icheylus的答复的评论。
通过像这样分配回调
callback = require('functions').prose()您正在尝试将函数的输出分配给回调。如果您的函数返回了一个函数,但是您的函数没有返回任何内容,这将是可行的。
因此,一个简单的调整就是只删除()
callback = require('functions').prose或者,如果函数在自动命令的回调中非常简单,甚至可以创建函数。
local textedit = vim.api.nvim_create_augroup('textedit', {clear = true})
vim.api.nvim_create_autocmd({"BufEnter", "BufNew"}, {
group = "textedit",
pattern = {"*.adoc", "*.md", "*.tex"},
callback = function()
vim.o.fdo:append('search')
vim.bo.virtualedit = block
-- more commands
end,
})https://stackoverflow.com/questions/73522082
复制相似问题