在Neovim中,如何在上次关闭的同一行号上打开文件?

发布于 2025-02-12 15:34:46 字数 214 浏览 0 评论 0原文

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

此代码在VIM中有效。它是vimscript的语法。它也可以在Neovim的配置文件init.vim中使用。我如何在init.lua中实现相同的效果?

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("
quot;) | exe "normal! g'\"" | endif

This code is valid in vim. It is the syntax of vimscript. It can also work in neovim's configuration file init.vim. how can I achieve the same effect in init.lua?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时间海 2025-02-19 15:34:46

在0.7.2上测试,如果不可用,则该版本可能太低。

vim.api.nvim_create_autocmd("BufReadPost", {
    pattern = {"*"},
    callback = function()
        if vim.fn.line("'\"") > 1 and vim.fn.line("'\"") <= vim.fn.line("$") then
            vim.api.nvim_exec("normal! g'\"",false)
        end
    end
})

Tested on 0.7.2, if not available, the version may be too low.

vim.api.nvim_create_autocmd("BufReadPost", {
    pattern = {"*"},
    callback = function()
        if vim.fn.line("'\"") > 1 and vim.fn.line("'\"") <= vim.fn.line("
quot;) then
            vim.api.nvim_exec("normal! g'\"",false)
        end
    end
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文