¿Alguien sabe cómo cerrar un buffer en VIM cuando usa NERDTree sin estropear todas sus ventanas? NERD Tree normalmente divide su pantalla en dos ventanas verticales (el navegador a su izquierda, y luego su ventana principal a la derecha). Si cierra un búfer, entonces se reduce a una ventana gigante de búsqueda de archivos. Si selecciona otro archivo, abre una segunda ventana pero la separa horizontalmente. ¿Algunas ideas?Árbol VIM y NERD - cerrar un buffer correctamente
Respuesta
No uso NERD Tree, pero si entiendo correctamente, desea cerrar un búfer sin cerrar una ventana. Si mi razonamiento es correcto, prueba este script.
" 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
funciona para mí en Vim 7.3 y 4.1.0 NERDTree.
Sí, acaba de actualizar MacVim a 7.3, ahora también funciona para mí. – mxgrn
Hm, estoy en Vim 7.3 y NERDTree 4.1 en Ubuntu 12.04 y todavía tengo el problema de OP. – Milimetric
No funciona para mí en Vim 7.4, NERDTree 4.2.0 en una máquina con Windows 7. – Juan
El complemento bufkill también parece solucionar este problema.
probar este mapeo: nnoremap <leader>q :bp<cr>:bd #<cr>
Funciona de maravilla y tan simple :) – newUserNameHere
Absolutamente hermosa solución. Estaba en la punta de mi lengua. – cbartondock
- 1. vim y extensión de árbol NERD: agregando un archivo
- 2. vim y Árbol NERD: ¿Puede Tree NERD persistir en todas las pestañas de MacVim?
- 3. ¿Cerrar URLConnection y InputStream correctamente?
- 4. Python in Vim buffer?
- 5. Cerrar correctamente un socket TCP
- 6. Refresh Vim buffer
- 7. ¿Qué es un "buffer" en VIM?
- 8. Vim script: Buffer/CheatSheet Toggle
- 9. ¿Cómo modificar un buffer Vim con un script python?
- 10. ¡Juego! no cerrar H2 correctamente
- 11. ¿Cómo cerrar IPython Notebook correctamente?
- 12. ¿Por qué mi nerd tree tiene estos caracteres extraños?
- 13. Deshacer Cerrar pestaña en Vim
- 14. ¿Cómo puedo ejecutar vim para ejecutar perltidy en un buffer?
- 15. ¿Cómo cerrar correctamente el servidor asio tcp?
- 16. ¿Cómo arreglar el buffer en una ventana en vim?
- 17. Cómo cerrar correctamente un Entity Manager en la doctrina
- 18. salir automáticamente de vim si NERDTree es pasado y solo buffer de
- 19. tComment vs. The NERD Commenter
- 20. cómo salir de un buf en vim
- 21. plugin de árbol de proyecto para vim
- 22. NERD comentarista: Cómo crear un comentario en un rango
- 23. Vim: Abra cada buffer en una nueva pestaña
- 24. ocurrencias de conteo en Vim sin marcar el buffer cambiaron
- 25. Detectando si existe buffer de solución rápida en VIM
- 26. ¿Cómo construir un árbol y?
- 27. ¿Debo cerrar manualmente un ifstream?
- 28. Vim no funciona correctamente con símbolos cirílicos
- 29. Cómo crear un mapa de teclas para abrir y cerrar la ventana de revisión en Vim
- 30. ¿Cómo descargo la salida de un comando externo a un nuevo buffer en Vim?
impresionante ... eso es exactamente lo que estaba buscando –
thakns, funciona muy bien - y útil no sólo para NERDTree! – nihique