Vim, NERDtree not recovered in session restore

前端 未结 6 1107
没有蜡笔的小新
没有蜡笔的小新 2021-01-30 17:49

When I have a NERDtree panel and I save a Vim session (mksession [filename]), then open the session (vim -S filename), the panel is opened and tagged \"NERDtree\" but is not pop

6条回答
  •  花落未央
    2021-01-30 18:29

    Just decided to deal with this very issue myself. In my case, the session is created when I quit Vim with the following in my vimrc:

    autocmd VimLeave * mksession! [filename]

    I was also trying to open NERDTree automatically when Vim opened with:

    autocmd VimEnter * NERDTree

    The result was that my session opened with two instances of NERDTree, like described in the original post. My solution was to simply close NERDTree before saving the session, that way my auto-open call would only open the one instance of NERDTree.

    My Solution

    " Save session on quitting Vim
    autocmd VimLeave * NERDTreeClose
    autocmd VimLeave * mksession! [filename]
    
    " Restore session on starting Vim
    autocmd VimEnter * call MySessionRestoreFunction()
    autocmd VimEnter * NERDTree
    

    It's working like a charm for me so far. Hope this helps.

提交回复
热议问题