NERDTree를 사용할 때 VIM의 버퍼를 닫는 방법을 아는 사람이 있습니까? NERD Tree는 일반적으로 디스플레이를 두 개의 수직 창 (왼쪽의 브라우저, 오른쪽의 기본 창)으로 나눕니다. 버퍼를 닫으면 하나의 거대한 파일 탐색 창으로 축소됩니다. 다른 파일을 선택하면 두 번째 창이 열리고 수평으로 분리됩니다. 어떤 아이디어?VIM 및 NERD 트리 - 적절하게 버퍼 닫기
답변
나는 NERD 트리를 사용하지 않지만, 올바르게 이해하면, 창을 닫지 않고 버퍼를 닫으려고합니다. 내 논리가 맞으면이 스크립트를 사용해보십시오.
" Delete buffer while keeping window layout (don't close buffer's windows).
" Version 2008-11-18 from http://vim.wikia.com/wiki/VimTip165
if v:version < 700 || exists('loaded_bclose') || &cp
finish
endif
let loaded_bclose = 1
if !exists('bclose_multiple')
let bclose_multiple = 1
endif
" Display an error message.
function! s:Warn(msg)
echohl ErrorMsg
echomsg a:msg
echohl NONE
endfunction
" Command ':Bclose' executes ':bd' to delete buffer in current window.
" The window will show the alternate buffer (Ctrl-^) if it exists,
" or the previous buffer (:bp), or a blank buffer if no previous.
" Command ':Bclose!' is the same, but executes ':bd!' (discard changes).
" An optional argument can specify which buffer to close (name or number).
function! s:Bclose(bang, buffer)
if empty(a:buffer)
let btarget = bufnr('%')
elseif a:buffer =~ '^\d\+$'
let btarget = bufnr(str2nr(a:buffer))
else
let btarget = bufnr(a:buffer)
endif
if btarget < 0
call s:Warn('No matching buffer for '.a:buffer)
return
endif
if empty(a:bang) && getbufvar(btarget, '&modified')
call s:Warn('No write since last change for buffer '.btarget.' (use :Bclose!)')
return
endif
" Numbers of windows that view target buffer which we will delete.
let wnums = filter(range(1, winnr('$')), 'winbufnr(v:val) == btarget')
if !g:bclose_multiple && len(wnums) > 1
call s:Warn('Buffer is in multiple windows (use ":let bclose_multiple=1")')
return
endif
let wcurrent = winnr()
for w in wnums
execute w.'wincmd w'
let prevbuf = bufnr('#')
if prevbuf > 0 && buflisted(prevbuf) && prevbuf != w
buffer #
else
bprevious
endif
if btarget == bufnr('%')
" Numbers of listed buffers which are not the target to be deleted.
let blisted = filter(range(1, bufnr('$')), 'buflisted(v:val) && v:val != btarget')
" Listed, not target, and not displayed.
let bhidden = filter(copy(blisted), 'bufwinnr(v:val) < 0')
" Take the first buffer, if any (could be more intelligent).
let bjump = (bhidden + blisted + [-1])[0]
if bjump > 0
execute 'buffer '.bjump
else
execute 'enew'.a:bang
endif
endif
endfor
execute 'bdelete'.a:bang.' '.btarget
execute wcurrent.'wincmd w'
endfunction
command! -bang -complete=buffer -nargs=? Bclose call <SID>Bclose('<bang>', '<args>')
nnoremap <silent> <Leader>bd :Bclose<CR>
nnoremap <silent> <Leader>bD :Bclose!<CR>
:bd
은 Vim 7.3 및 NERDTree 4.1.0에서 작동합니다.
예, 방금 MacVim을 7.3으로 업데이트했습니다. 이제 나에게도 적합합니다. – mxgrn
흠, 나는 Vim 7.3과 NerDTree 4.1을 Ubuntu 12.04에 탑재하고 있으며 여전히 OP 문제가 있습니다. – Milimetric
Windows 7 컴퓨터에서 Vim 7.4, NERDTree 4.2.0에서 작동하지 않습니다. – Juan
bufkill 플러그인도이 문제를 해결하는 것으로 보입니다.
이 매핑을 시도해보십시오 nnoremap <leader>q :bp<cr>:bd #<cr>
위대한 너무 간단하게 :) – newUserNameHere
절대적으로 화려한 솔루션입니다. 그것은 내 혀끝에있었습니다. – cbartondock
멋진 ... 정확히 내가 –
thakns 무엇을 찾고 있었다, 위대한 작품을 이잖아 - 유용한뿐만 아니라, NERDTree을 위해! – nihique