二、用winmanager合并显示NERDTree和TagList

来源:互联网 发布:淘宝的盈利模式是什么 编辑:程序博客网 时间:2024/04/29 09:03
七、退出缓冲区时,自动退出vim

这个功能是参考了taglist的自动退出功能,在taglist.vim中修改的。

函数:function! s:Tlist_Window_Exit_Only_Window()中的winbunr(2)改为winbunr(3),即只剩2个窗口时关闭,考虑到2个窗口肯定是同时存在,所以这样还是可行的:

function! s:Tlist_Window_Exit_Only_Window()
    " Before quitting Vim, delete the taglist buffer so that
    " the '0 mark is correctly set to the previous buffer.
    if v:version < 700
    if winbufnr(3) == -1
        bdelete
        quit
    endif
    else
    if winbufnr(3) == -1
        if tabpagenr('$') == 1
           " Only one tag page is present
           bdelete
           quit
        else
           " More than one tab page is present. Close only the current
           " tab page
           close
        endif
    endif
    endif
endfunction

同时在vimrc中需要设置:
let Tlist_Exit_OnlyWindow=1

原来的设置注释掉。加好后,发现每次打开winmanager都会出现一个空白的buffer。试验了好多次,但是Nerd_tree调用的函数就 是会打开一个新窗口。因为如此,将bufExplorer和NERD_Tree放在一起会显示不正常。NERD_Tree放在下面的窗口也会出错,实在比 较郁闷。。。。看了下NERD_Tree的代码,没看懂,只好再次改winmanager的代码了。

打开winmanager.vim,找到函数function! <SID>ToggleWindowsManager(),加入两行,修改后整个函数如下:

" toggle showing the explorer plugins.

function! <SID>ToggleWindowsManager()

    if IsWinManagerVisible()

        call s:CloseWindowsManager()

    else

        call s:StartWindowsManager()

"        NERD_tree need this. 打开时会有一个空白窗口,要把他关闭。

        exe '1wincmd w'

        exe 'q'

    end

endfunction

加个注释,以免以后忘掉了,如果不想用nerd_Tree了,这2句话还得删掉。

 

另外打开时的命令和关闭时的命令也得同时修改了,试验了很多次:

taglist.vim中,找到下面的代码:

        " Exit Vim itself if only the taglist window is present (optional)
       "        if g:Tlist_Exit_OnlyWindow
       "        autocmd BufEnter __Tag_List__ nested
       "            \ call s:Tlist_Window_Exit_Only_Window()
       "        endif
      将这段代码修改为:
      " Exit Vim itself if only the taglist window is present (optional)
       let s:NERDTreeBufName = 'NERD_tree_'
       if g:Tlist_Exit_OnlyWindow
           augroup Exit_onlywindow
               "当进入Nerd_Tree的buffer时也检测是否需要退出
               exec "autocmd BufEnter ". s:NERDTreeBufName .
                           \"* call s:Tlist_Window_Exit_Only_Window()"
               autocmd BufEnter __Tag_List__ nested
                   \ call s:Tlist_Window_Exit_Only_Window()
           augroup end
       endif

       winmanager中:刚才添加的自动执行命令要改为:
       "set auto open Winmanager
       if g:AutoOpenWinManager
       "    autocmd VimEnter * nested call s:StartWindowsManager()|1wincmd w 
           autocmd VimEnter * nested call s:StartWindowsManager()|1wincmd w|q
       endif

       这样所有的功能就实现了。在taglist窗口使用ctrl+n可以转换到bufexplorer窗口。
0 0
原创粉丝点击