Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim close buffer with nerdtree

Tags:

vim

nerdtree

My current use case is: I have a buffer open with a NERDTree (Left) and 1 with a file being edited (Right)

Lets also assume 2 other files in background buffers are open as well.

enter image description here

If i press c (shortcut for closing buffer, basically :bd), the Right side is gone and only the left side is displayed. But when closing a buffer, i would expect that vim will close the current file buffer and keep the right side to open one of the buffers that are in the background.

enter image description here

How do I achieve the expected behavior?

like image 349
user3470707 Avatar asked Aug 04 '15 09:08

user3470707


People also ask

How do I close NERDTree in Vim?

If you want to close NERDTree window make sure you are inside the NERDTree menu. You can switch windows by using ctrl+w then type :q to close NERDTree window so that you will be left with the window for editing your code.

How do I close a Vim buffer?

Assuming the default backslash leader key, you can also press \bd to close (delete) the buffer in the current window (same as :Bclose ).

How do I switch between vim and NERDTree?

I normally switch screen in vim using ctrl+h or ctrl+l to switch between NerdTree and vim main window. Vim8 got :term command to bring up terminal which is great!

How do I delete a file in NERDTree?

Press m to bring up the NERDTree Filesystem Menu. This menu allows you to create, rename, and delete files and directories.


2 Answers

You can use

nnoremap c :bp\|bd #<CR>

Which will first go to the previous buffer, then delete the last buffer. This way it will both close the buffer and go to the previous one.

like image 57
edi9999 Avatar answered Nov 04 '22 10:11

edi9999


May be bufkill can solve this issue for you.

like image 40
mustafagonul Avatar answered Nov 04 '22 09:11

mustafagonul