Vim NERDTree +标签栏未按预期工作

时间:2015-11-04 07:28:21

标签: vim nerdtree tagbar

我刚刚使用vundle在vim中安装了NERDTree和Tagbar。当我一次使用一个插件时,一切正常,但当我尝试打开一个而另一个已打开导致问题时。

这是一个打开NERDTree的vim图

+------+---------------+
|      |               |
|      |               |
|      |               |
|      |               |
|      |               |
|      |               |
|      |               |
|      |               |
+------+---------------+

在我用NERDTree打开Tagbar后打开

++---------------+------+
||               |      |
||               |      |
||               |      |
||               |      |
||               |      |
||               |      |
||               |      |
||               |      |
+--+-------------+------+

NERDTree现在被压缩到左边。

如果我尝试切换NERDTree,它会一直压扁直到我切换标签栏。 有什么特别的东西我必须做才能让两个人放得好吗?

vim非常新,所以不确定除了我使用vim 7.4之外还有什么信息,我不知道如何找到我正在使用的插件版本。

我的.vimrc是

set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'fatih/vim-go'
Plugin 'majutsushi/tagbar'
Plugin 'fatih/molokai'
Plugin 'tmhedberg/SimpylFold'
Plugin 'Valloric/YouCompleteMe'
Plugin 'bling/vim-airline'
Plugin 'scrooloose/syntastic'
Plugin 'nsf/gocode', {'rtp': 'vim/'}
Plugin 'scrooloose/nerdtree'
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
Plugin 'flazz/vim-colorschemes'
Plugin 'kien/ctrlp.vim'
call vundle#end()

filetype plugin indent on
"Ok. Done.

set backspace=indent,eol,start
set number
set nowrap
set hidden
inoremap jk <ESC>

let mapleader=","

" we also want to get rid of accidental trailing whitespace on save
autocmd BufWritePre * :%s/\s\+$//e

" =================================================
" ----------
" Navigation
" ----------
" tell vim to allow you to copy between files, remember your cursor
" position and other little nice things like that
" split navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

" =================================================
" -------------
" Golang Config
" -------------
" tell vim to allow you to copy between files, remember your cursor
" position and other little nice things like that
set viminfo='100,\"2500,:200,%,n~/.viminfo

" Open file at a position where it was last left.
au BufWinLeave *.go mkview
au BufWinEnter *.go silent loadview

" use goimports for formatting
let g:go_fmt_command = "goimports"

" turn highlighting on
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1

" =================================================
" ---------
" Syntastic
" ---------
let g:syntastic_go_checkers = ['go', 'golint', 'errcheck']
" we want to tell the syntastic module when to run
" we want to see code highlighting and checks when  we open a file
" but we don't care so much that it reruns when we close the file
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

" Open go doc in vertical window, horizontal, or tab
au Filetype go nnoremap <leader>v :vsp <CR>:exe "GoDef" <CR>
au Filetype go nnoremap <leader>s :sp <CR>:exe "GoDef"<CR>
au Filetype go nnoremap <leader>t :tab split <CR>:exe "GoDef"<CR>

" =================================================
" -----------
" Color setup
" -----------
set t_Co=256
syntax enable
set background=dark

try
  colorscheme distinguished
catch E185
endtry

" =================================================
" -------
" Airline
" -------
" display fonts correctly for airline
set encoding=utf-8
" Allows the bottom status line for airline to be shown
set laststatus=2
let g:airline_powerline_fonts=1
" Enable the list of buffers
let g:airline#extensions#tabline#enabled = 1
" Show just the filename
let g:airline#extensions#tabline#fnamemod = ':t'

" =================================================
" --------
" NerdTree
" --------
map <C-n> :NERDTreeToggle<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
let g:NERDTreeWinSize = 40


" =================================================
" ----
" Tmux
" ----
" let g:tmux_navigator_save_on_switch = 1

" =================================================
" -----------
" CodeFolding
" -----------
" Enable folding
set foldmethod=indent
set foldlevel=99
" Enable folding with the spacebar
nnoremap <space> za

" =================================================
" ------
" TagBar
" ------
nmap <silent> <leader>tt :TagbarToggle<CR>
let g:tagbar_autoclose = 0
let g:tagbar_left = 0
let g:tagbar_expand = 0

let g:tagbar_type_go = {
    \ 'ctagstype' : 'go',
    \ 'kinds'     : [
    \ 'p:package',
    \ 'i:imports:1',
    \ 'c:constants',
    \ 'v:variables',
    \ 't:types',
    \ 'n:interfaces',
    \ 'w:fields',
    \ 'e:embedded',
    \ 'm:methods',
    \ 'r:constructor',
    \ 'f:functions'
    \ ],
    \ 'sro' : '.',
    \ 'kind2scope' : {
    \ 't' : 'ctype',
    \ 'n' : 'ntype'
    \ },
    \ 'scope2kind' : {
    \ 'ctype' : 't',
    \ 'ntype' : 'n'
    \ },
    \ 'ctagsbin'  : 'gotags',
    \ 'ctagsargs' : '-sort -silent'
\ }

" =================================================
" ------
" Ctrl-P
" ------
set wildignore+=*/tmp/*,*.so,*.swp,*.zip
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
let g:ctrlp_user_command = 'find %s -type f'


" NERDTree and TagBar don't play nicly together, when one is open and then
" open another one the inital one gets squished this will toggle one or the
" other only having one open at a time
function! ToggleNERDTreeAndTagbar()
"    let 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
    NERDTreeClose
    TagbarOpen
    elseif tagbar_open
    TagbarClose
    NERDTree
    else
    NERDTree
    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 个答案:

答案 0 :(得分:0)

如果有其他人遇到此问题。我的解决方案是删除这一行

au BufWinEnter *.go silent loadview

答案 1 :(得分:0)

我在autocmd事件中移除了BufWinEtner,现在它很好。

因此autocmd事件上的任何BufWinEnter可能会触发此问题。

谢谢@杰夫的提示。

相关问题