英文:
Lua neovim plugin load nvim_buf_clear_namespace when textchange
问题
I started using neovim recently and for a learning Example i tried to create a basic plugin to update packages for node modules inside the package.json
The idea is when the text changes
or when trying to undo
i clear the buffer.
Calling this function : lua Clear_highlights()
do the job but it's seems when the text changes
or undo
seems not triggering the function Clear_highlights()
am for sure missing something if someone can help me catch this will be awesome.
Thank you.
line 20 : Github repo
-- Clear buffer
Clear_highlights = function()
vim.api.nvim_buf_clear_namespace(0, require("nodePackageCheck").Config.get_namespace_id(), 0, -1)
end
vim.cmd([[autocmd! TextChanged,TextChangedI, BufWritePost * lua Clear_highlights()]])
英文:
I started using neovim recently and for a learning Example i tried to create a basic plugin to update packages for node modules inside the package.json
The idea is when the text changes
or when trying to undo
i clear the buffer.
Calling this function : lua Clear_highlights()
do the job but it's seems when the text changes
or undo
seems not triggering the function Clear_highlights()
am for sure missing something if someone can help me catch this will be awesome.
Thank you.
line 20 : Github repo
-- Clear buffer
Clear_highlights = function()
vim.api.nvim_buf_clear_namespace(0, require("nodePackageCheck").Config.get_namespace_id(), 0, -1)
end
vim.cmd([[autocmd! TextChanged,TextChangedI, BufWritePost * lua Clear_highlights()]])
答案1
得分: 1
vim.cmd([[autocmd! TextChanged,TextChangedI, BufWritePost * lua Clear_highlights()]])
autocmd!
用于删除处理程序/组,而不是定义它们。删除感叹号 (!
)。- 随机的空格会混淆 vim 的解析器:在这里它将
BufWritePost
视为“模式”,*
为处理程序(命令)的起始。
尝试这个改写:
vim.cmd([[autocmd TextChanged,TextChangedI,BufWritePost * lua Clear_highlights()]])
英文:
vim.cmd([[autocmd! TextChanged,TextChangedI, BufWritePost * lua Clear_highlights()]])
autocmd!
is for deleting handlers/groups, not defining them. Remove the bang (!
).- Random whitespace confuses vim's parser: here it treats
BufWritePost
as the "pattern", and*
as the start of the handler (command).
Try this instead:
vim.cmd([[autocmd TextChanged,TextChangedI,BufWritePost * lua Clear_highlights()]])
答案2
得分: 0
我的最终解决方案是在普通模式下重新映射 undo
并调用 Clear_highlights()
。
vim.api.nvim_set_keymap("n", "u", ":undo<CR>:lua Clear_highlights()<CR>", { noremap = true, silent = true })
英文:
My final solution was a remapping undo
in normal mode and call Clear_highlights()
with.
vim.api.nvim_set_keymap("n", "u", ":undo<CR>:lua Clear_highlights()<CR>", { noremap = true, silent = true })
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论