Vim, NERDtree not recovered in session restore

前端 未结 6 1109
没有蜡笔的小新
没有蜡笔的小新 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 18:10

    The easiest way to make NERDTree act as expected with sessions is probably to patch NERD_tree.vim, adding an autocommand to the NERDTree autocommand group (right after the augroup NERDTree line):

    exec "autocmd BufEnter ". s:NERDTreeBufName ."* call initNerdTreeInPlace(\"\")"
    

    It's not extensively tested, but this seems to work for me with several layouts and with different numbers of NERDTree windows open.

    Edit: Actually, this doesn't work so great because NERDTree has primary and secondary windows, and there's no indication in the session file whether a NERDTree buffer is one or the other. It looks like adding reliable support for this to the plugin wouldn't be that big a challenge, but it's more than trivial. In the meantime, for simple cases, adding the following autocommand (instead of the one above) might do what you want:

    exec "autocmd BufEnter ". s:NERDTreeBufName ."* :NERDTreeToggle | :NERDTreeToggle"
    

提交回复
热议问题