root
root

Reputation: 91

Vim and NERDTree - Clear [No name] from buffers

I am new to Vim and NERDTree, and I am trying to understand why a buffer appears as [No name] after I delete it using :bd. I want to keep my NERDTree clean so I wonder if there is a way to remove the [No name].

For example,

My buffers

The l.py file is the one I am working on, and the [No name] ones are the files that I already closed (with :bd). I don't want them to show up at all because it looks messy.

Thanks!

Upvotes: 1

Views: 2375

Answers (1)

Peter Rincker
Peter Rincker

Reputation: 45107

I doubt NerdTree is putting buffers into your status line. I imagine some status line plugin like vim-airline. It would probably be best to look at your status line plugin's documentation for how to make customizations or submit an issue on the plugin's bug tracker.

We need to talk...

The biggest problem I see is that you are trying to use the status line as a makeshift "tab bar". Most other editors use a tab bar as a way to manage documents, but not Vim. This makeshift "tab bar" is probably a bad idea once you start using more files or more complicated workflows with splits or tabs (Vim's tabs are different).

Oh yeah? What about Buftabline, Airline, BufTabs, MiniBufExpl, ...?

All these plugins do is show you your currently listed buffers. Maybe with some kind of positioning information so that you feel comfortable cycling via :bnext and :bprevious (or whatever mappings you might be using) through your buffer list.

Now that is great and all, these plugins have recreated other editor's version of tabs, but Vim already let you cycle through buffers without these plugins. The only thing missing was a menu which :ls will gladly do for you without wasting any screen real-estate.

Imagine having 10, 25, 50, or 100+ buffers open. How is your Buftabline going to handle that? My bet is not well. You need to stop reaching for simple tools like :bnext / :bprev and start reaching for a power tool like :b.

Behold the power of :b

The :b command can take a buffer number to switch directly to a buffer. Far more interesting, :b can take a partial filename.

:b partial-name

Need more power in your :b?

  • Uses tab completion
  • Uses <c-d> to list out completions
  • Accepts globs. e.g. :b *foo
  • Use ** to descend into directories. e.g. :b foo/**/bar
  • Don't forget to add set hidden to your vimrc. See :h 'hidden'

Why ride a bike when you can fly?

Flying vs cycling

taken from Bairui's collection of Vim infographics.

You can use a simple mapping to leverage both :ls and :b:

nnoremap <leader>b :ls<cr>:b<space>

Now you can travel directly to you buffer you want. No more cycling.

But I like plugins

Who doesn't like a good plugin. As a matter a fact if you are looking for a nice buffer switching plugin then I would recommend you look into a nice fuzzy finder like CtrlP to aid you in switching between buffers. A fuzzy finder actually adds value to switching between buffers by getting you there faster with less typing.

Conclusion

Eventually you workflow will require you to use more than 3 buffers at a time. At that moment I would suggest you take another look at the :b command or at the very least get a nice fuzzy finder. It will save you time and effort.

So stop riding your bike when you can fly.

Upvotes: 7

Related Questions