任何让 (g)vim 显示的机会书呆子树和标签栏彼此上方留下编辑文件?
+-----------+-------------+
| nerd tree | edited file |
| contents | |
+-----------+ |
| tagbar | |
| contents | |
+-----------+-------------+
我想以.vimrc
某种方式完成它。
到目前为止,我的相关部分.vimrc
如下所示:
" NERDTree shortcut
:nmap \e :NERDTreeToggle<CR>
" tagbar settings
let g:tagbar_left=1
nnoremap <silent> <F9> :TagbarToggle<CR>
然而,当显示时,它们显示如下:
+----------+-----------+-------------+
| tagbar | nerd tree | edited file |
| contents | contents | |
| | | |
| | | |
| | | |
+----------+-----------+-------------+
答案1
我在问题“How to open or close NERDTree and Tagbar with <leader>\?”中使用了 Jan Larres 编写的 vim 函数。并修改它(我只添加了 wincmd 命令)以使我的 vim 看起来像这样:
+-----------+-------------+
| Tagbar | file |
| contents | |
+-----------+ |
| NERDTree | |
| contents | |
+-----------+-------------+
功能! ToggleNERDTreeAndTagbar() 让 w:jumpbacktohere = 1
" Detect which plugins are open
if exists('t:NERDTreeBufName')
let nerdtree_open = bufwinnr(t:NERDTreeBufName) != -1
else
let nerdtree_open = 0
endif
let tagbar_open = bufwinnr('__Tagbar__') != -1
" Perform the appropriate action
if nerdtree_open && tagbar_open
NERDTreeClose
TagbarClose
elseif nerdtree_open
TagbarOpen
wincmd J
wincmd k
wincmd L
elseif tagbar_open
NERDTree
wincmd J
wincmd k
wincmd L
else
NERDTree
TagbarOpen
wincmd J
wincmd k
wincmd L
endif
" Jump back to the original window
for window in range(1, winnr('$'))
execute window . 'wincmd w'
if exists('w:jumpbacktohere')
unlet w:jumpbacktohere
break
endif
endfor
endfunction
nnoremap <leader>\ :call ToggleNERDTreeAndTagbar()<CR>
答案2
那会很困难。两者都在内部使用:NERDTreeToggle
,并且无法简单地重新配置或连接到它。:TagbarToggle
:vsplit
您必须为您的触发器编写包装器\e
来<F9>
检测当前窗口布局,进行切换,然后抖动窗口以满足您的要求。仅最后一步就已经相当复杂了。您必须使用 向下推侧边栏窗口之一:wincmd J
,然后再次将右侧文件窗口设为全高 win :wincmd L
。
你看,这并不容易。相反,我所做的就是始终只激活其中一个插件。我的个人映射会检查打开的侧边栏,并在切换 NERD_tree 之前关闭例如标签栏。这更容易实施。