2

vundleを使用してvimにNERDTreeとTagbarをインストールしました。一度に 1 つのプラグインを使用するとすべて正常に動作しますが、もう 1 つのプラグインを既に開いているときに別のプラグインを開こうとすると問題が発生します。

これは、NERDTree を開いた状態の vim の図です。

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

NERDTreeを開いた状態でTagbarを開いた後

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

NERDTree が左に押しつぶされるようになりました。

NERDTree を切り替えようとすると、タグバーを切り替えるまで押しつぶされたままになります。2つをうまく配置するために私がしなければならない特別なことはありますか?

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>
4

2 に答える 2

0

イベントで削除autocmdしますが、今は問題ありません。BufWinEtner

そのためautocmdBufWinEnterイベントが発生すると、この問題が発生する可能性があります。

@ジェフのヒントに感謝します。

于 2017-01-06T02:10:14.327 に答える
0

他の誰かがこの問題に遭遇した場合。私にとっての解決策は、この行を削除することでした

au BufWinEnter *.go silent loadview
于 2015-11-06T05:56:06.313 に答える