Vim, NERDtree not recovered in session restore

前端 未结 6 1155
没有蜡笔的小新
没有蜡笔的小新 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:21

    I had the same problem and during my research i found two solutions:

    You can use a plugin called "session.vim", which has a basic support for restoring the NERDTree. You can find it here: http://www.vim.org/scripts/script.php?script_id=3150

    I found out for myself that this plugin is not for me, so i took another approach. You can configure vim to automatically set the directory of your buffer equal to your working directory.

    autocmd BufEnter * lcd %:p:h
    

    Since the NERDTree opens the working directory when you open it up the first time, you are already where you want to be!

    Just open the NERDTree after you opened up your file or your session in this case.

    However, since the magic will work only for the first time within one tab, you can use the following command to let the NERDTree find your file in the tree.

    map r :NERDTreeFind
    

    To unclutter the tree just go up a few directorys as you wish using the "p" command and then type "C".

    I found out the commands thanks to the guys in this post:

    https://superuser.com/questions/195022/vim-how-to-synchronize-nerdtree-with-current-opened-tab-file-path

提交回复
热议问题