问题描述
由于每次分割和加载每个窗口有点麻烦,我使用以下方法保存了会话:
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
或
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 terminalbut doesn't help much.
有人知道吗?
推荐答案
我遇到了同样的问题;如果我在 sessionoptions 中保存没有 'options' 的会话,当我重新加载 Vim 时,缓冲区会重新加载,但没有语法高亮显示.
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.
解决方案是在重新加载时使用带有嵌套的 autocmd.
The solution is to use an autocmd with nested when reloading.
Wikia 有一篇内容丰富的文章关于加载和保存会话.底部提到了嵌套"选项.
Wikia has an extensive article about loading and saving sessions. The 'nested' option is mentioned at the bottom.
我使用这个 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
这篇关于恢复上一个 vim 会话后语法高亮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!