恢复以前的 vim 会话后语法突出显示不起作用

发布于 2025-01-05 17:50:34 字数 425 浏览 4 评论 0原文

因为每次划分和加载每个窗口有点麻烦,所以我使用:保存了我的会话

mksession ~/session1.vim

,并使用:恢复了它,

vim -S session1.vim

或者

source session1.vim

它完美地恢复了前一个会话,但根本不显示任何语法突出显示。

我在这里发现了类似的问题:终端中会话恢复后没有语法突出显示 但没有多大帮助。

有人知道吗?

since dividing and loading each windows every time are kinda bothersome, I saved my session using:

mksession ~/session1.vim

and restored it using:

vim -S session1.vim

or

source session1.vim

it restores the previous session perfectly, but doesn't show any syntax highlighting at all.

I found a similar question over here: No syntax highlighting after session restore in terminal
but doesn't help much.

does anyone have any idea?

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

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

发布评论

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

评论(3

┾廆蒐ゝ 2025-01-12 17:50:34

我也有同样的问题;如果我在 sessionoptions 中保存没有“选项”的会话,那么当我重新加载 Vim 时,缓冲区会重新加载,但不会突出显示语法。

解决方案是在重新加载时使用嵌套的 autocmd。

Wikia 有一篇内容丰富的文章关于加载和保存会话。底部提到了“嵌套”选项。

我使用 这个 StackOverflow 答案,如下:

fu! SaveSess()
  execute 'mksession! ' . getcwd() . '/.session.vim'
endfunction

fu! RestoreSess()
  if filereadable(getcwd() . '/.session.vim')
    execute 'so ' . getcwd() . '/.session.vim'
    if bufexists(1)
      for l in range(1, bufnr('
))
        if bufwinnr(l) == -1
          exec 'sbuffer ' . l
        endif
      endfor
    endif
  endif
endfunction

autocmd VimLeave * call SaveSess()
autocmd VimEnter * nested call RestoreSess()

set sessionoptions-=options  " Don't save options

I had the same problem; if I saved sessions without 'options' in sessionoptions, when I reloaded Vim, the buffers were reloaded, but without syntax highlighting.

The solution is to use an autocmd with nested when reloading.

Wikia has an extensive article about loading and saving sessions. The 'nested' option is mentioned at the bottom.

I use a modified version of this StackOverflow answer, here it is:

fu! SaveSess()
  execute 'mksession! ' . getcwd() . '/.session.vim'
endfunction

fu! RestoreSess()
  if filereadable(getcwd() . '/.session.vim')
    execute 'so ' . getcwd() . '/.session.vim'
    if bufexists(1)
      for l in range(1, bufnr('
))
        if bufwinnr(l) == -1
          exec 'sbuffer ' . l
        endif
      endfor
    endif
  endif
endfunction

autocmd VimLeave * call SaveSess()
autocmd VimEnter * nested call RestoreSess()

set sessionoptions-=options  " Don't save options
只是我以为 2025-01-12 17:50:34

我可以使用 Obsession vim 插件和 Neovim 来解决这个问题。该线程中的答案帮助我找到了解决方案,尽管就我而言,此处提供的解决方案并未立即起作用。

我查看了 sessionoptions 帮助页面。对我来说,解决问题的设置是set sessionoptions+=localoptions。然后在配置中使用此选项重新加载 vim 并重新加载语法突出显示后,突出显示将保存在会话中。

I can across this Issue using the Obsession vim plugin and Neovim aswell. The answer in this thread helped me finding the solution although in my case the solution provided here didn't work immediately.

I took a look at the sessionoptions help page. For me the setting that fixed the problem was set sessionoptions+=localoptions. Then after reloading vim with this option in the config and after reloading the syntax highlighting, the highlighting was saved in the session.

初熏 2025-01-12 17:50:34

我有同样的问题。我删除了会话文件,然后用 mks 重新创建了它,这解决了问题。可能是处于不一致的状态。

I had the same issue. I deleted my session file, I re-created it with mks and that fixed the issue. Probably it was in an inconsistent state.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文