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

后端 未结 3 1684
自闭症患者
自闭症患者 2021-02-07 06:22

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

mksession ~/session1.vim

and restored it usi

相关标签:
3条回答
  • 2021-02-07 06:55

    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.

    0 讨论(0)
  • 2021-02-07 07:00

    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
    
    0 讨论(0)
  • 2021-02-07 07:00

    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.

    0 讨论(0)
提交回复
热议问题