Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

His explanation on buffers isn't completely true, though. You can't have an unsaved non-visible buffer. Meaning, if you edit a buffer, you can't open another buffer in the same window without saving the edited one, first.


That's why so many new users turn to using tabs. Because they think they can't replace the current unsaved buffer they open another file in a tab. The result is very superficially similar to what you'd get in other editors but it is very different and full of pitfalls if you persist in treating them as regular tabs.

These two lines in your ~/.vimrc are enough to be able to work efficiently with buffers and windows and make tabs more useable:

    set hidden
    set switchbuf=useopen,usetab
The first makes it possible to replace the current unsaved buffer with another one.

The second allows you to jump to a buffer where it is (in another window, another tab) instead of replacing the current buffer with :b buffername.


Thanks! But it's too late for me - I already switched to emacs + evil-mode.


Any suggestions on getting started with emacs and evil?


To bad switchbuf doesn't actually work with :b.

Only buffer related split commands like :sbuffer, :sbnext


argh. :sb indeed.


Yup. The problem with vim is that it has way too many buttons you have to press to unbreak it.


You can if you enable the 'hidden' option.


Hmm, yes. :set hidden is recommended so often in pretty much every introductory tutorial that in places I've assumed people who have basic familiarity with Vim are already using it.

In retrospect this probably wasn't wise of me; I don't use it myself, and I still run into the occasional Vim guru online who doesn't either.

I've edited the post with a clarifying note and given you a footnote. Thanks.


He also says:

  It only goes away when you explicitly delete it with a call to :quit or :bdelete.
This isn't true. :bdelete makes the buffer an unlisted-buffer. :bwipeout actually removes the buffer completely.

http://vim.wikia.com/wiki/Vim_buffer_FAQ


Thanks for that; I clarified and gave you a footnote.


Np, it took me an embarrassingly long amount of time to grok Vims handling of Buffers, Tabs and Windows. I think your article is a nice introductory writeup on the subject. I wish I had it when I first started with Vim.

Also, as far as buffer handling goes, I really like the SelectBuf ( http://www.vim.org/scripts/script.php?script_id=107 ) plugin for listing and sorting open buffers ( including unlisted! ). CtrlP ( http://kien.github.com/ctrlp.vim/ ) works well for searching them.


not true. well, it kind of is if you don't configure your vim "right". any sensible configuration I've seen includes the "set hidden" option which will enable you to switch to another buffer w/o saving the current one. w/o this config option vim is barely usable imho.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: