简体   繁体   English

恢复上一个 vim 会话后语法高亮不起作用

[英]syntax highlighting doesn't work after restore a previous vim session

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?有人有什么主意吗?

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.如果我在 sessionoptions 中保存没有 'options' 的会话,当我重新加载 Vim 时,缓冲区会被重新加载,但没有语法高亮显示。

The solution is to use an autocmd with nested when reloading.解决方案是在重新加载时使用嵌套的 autocmd。

Wikia has an extensive article about loading and saving sessions . Wikia 有一篇关于加载和保存会话的大量文章。 The 'nested' option is mentioned at the bottom.底部提到了“嵌套”选项。

I use a modified version of this StackOverflow answer , here it is:我使用了这个 StackOverflow answer的修改版本,这里是:

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 can across this Issue using the Obsession vim plugin and Neovim aswell.我可以使用 Obsession vim 插件和 Neovim 解决这个问题。 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.我查看了 sessionoptions 帮助页面。 For me the setting that fixed the problem was set sessionoptions+=localoptions .对我来说,解决问题的设置是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.然后在配置中使用此选项重新加载 vim 并重新加载语法突出显示后,突出显示保存在会话中。

I had the same issue.我遇到过同样的问题。 I deleted my session file, I re-created it with mks and that fixed the issue.我删除了我的会话文件,我用 mks 重新创建了它并解决了这个问题。 Probably it was in an inconsistent state.可能它处于不一致的状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM