2015-11-04 26 views
0

我剛剛在vim中使用vundle安裝了NERDTree和Tagbar。當我一次使用一個插件時,一切正常,但當我嘗試打開一個插件而另一個已經打開時會導致問題。Vim NERDTree + tagbar不按預期方式工作

下面是VIM與NERDTree開放

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

後,我打開Tagbar與NERDTree開放

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

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> 
+0

開箱即用。您是否嘗試刪除/註釋掉與這兩個插件相關的所有配置選項?如:如果它使用默認設置,請嘗試逐行回收配置,並查看哪個設置導致問題。 – guessimtoolate

+0

@guessimtoolate謝謝你的建議。我發現了這個問題。看起來這是導致「au BufWinEnter * .go silent loadview」問題的線路 – Jeff

回答

0

如果任何人遇到了這個問題。對我來說,解決辦法是刪除此行

au BufWinEnter *.go silent loadview 
0

我刪除autocmdBufWinEtner事件,那麼它現在是很好的。

因此看起來任何autocmd上的BufWinEnter事件都可能觸發此問題。

謝謝@傑夫的提示。