5 ms·
The two "advanced" topics that I've never bothered to learn, despite my years of using vim, are registers and buffers. Thanks to the answers on SO and the comme
by Pewpewarrows 15y ago
The two "advanced" topics that I've never bothered to learn, despite my years of using vim, are registers and buffers. Thanks to the answers on SO and the comments here, I think I have a pretty good grasp of registers (the being able to paste yanked text after a delete would have saved me so much god-damn time).
So all that leaves is buffers. I've traditionally been using tabs and splits for all my editing multitasking, with NERDTree and Command-T to open new files quickly. Is there anything to be gained from me learning/using buffers at this point? I don't know what benefits they offer, and I've never had any problems with my current tab & split setup.
Any buffer evangelists out there that care to chime in?
- DEinspanjer 15y agoHidden buffers are the only important thing to me. I don't know if you might already have that turned on or not. If hidden buffers are enabled, you can open document A, make some changes, then open document B in the same window and you don't have to save the other document first. When you want to go back to it, you just use :b 1 If you use screen, you can think of buffers like windows. You can have multiple windows open but one is active at any moment, or you can split your screen into multiple regions and have multiple windows visible at the same time. In Vim, you can have multiple buffers open. You can interact with them one at a time through a single window or you can split the window and see multiple buffers at the same time. If you get used to using them like that, then things like the :bufdo command becomes handy for making changes to a bunch of docs at the same time and you can quickly bounce around documents without having to browse to them each time.
- mcantor 15y agoSurprise! You have been using buffers all this time. A "buffer" is just "a file in memory"; if you have 1 split on your screen, with a different file in each split, then you are viewing 2 buffers. The two things which will probably give you the biggest bang for your buck are: :ls Which lists all buffers currently in memory, and: :b Which supports tab completion, allowing you to instantly jump to any file with just a few keystrokes. You'll also probably enjoy Ctrl + 6 / Ctrl + ^, which swaps between two buffers. You'll need to do :set hidden before switching between buffers in a single window. Don't worry, though; if you try to quit without saving a modified buffer, or use :bd to delete a buffer without saving it, vim will yell at you.
- bsergean 15y ago:b also takes the buffer id. (reported by :ls). I sometimes write them down on a post-it when I have lots of files to memorize them ... :)
- yuvipanda 15y ago<leader>b is a good replacement for both :ls and :b if you're using Command-T (like grandparent is). I was surprised when I discovered that feature, since it isn't quite as advertised/popular as the file opening capabilities of Command-T
- Pewpewarrows 15y agoOh wow, that's an excellent find. That immediately made playing around with buffers much easier.
- yuvipanda 15y agoIndeed! I was using BufferExplorer and accidentally 'discovered' <leader>b. 30 minutes later, BufferExplorer was dead :)
- pyre 15y agoBufferExplorer is a good plugin to have around. <leader>be will give you a listing of all of your buffers and allow you to do things like hit 'd' to delete the buffer under the cursor.
- deleted 15y ago[deleted]
- donaq 15y agoI'm a recent buffer convert. Now I use them in combination with splits because there was this module I had to modify for work that involved >8 files. My monitor wasn't big enough to comfortably view 8 splits, so I learned how to use buffers. Also, you can use buffers and splits over ssh, but not tabs.
- subleq 15y agoWhy can't you use tabs over ssh? `gt`, `gT`, and `<n>gt` cycle forward through tabs, backwards, and go to the `n`th tab.
- donaq 15y agoOoh, I did NOT know that tabbing works in a non-GUI environment! Once again, Hacker News has humbled me. Thanks!
- derobert 15y agoYou should be able to use graphical tabs over ssh with either X11 forwarding (ssh -X user@host) or by using vim's remote file syntax: gvim sftp://user@host/path/to/file (see :help netrw)
- donaq 15y agoI should have been clearer, perhaps. I meant with servers that don't usually run X. However, that remote file syntax thing I did not know about. Thanks!
- derobert 15y agoThe servers don't need to run X. X runs on your machine. The servers will need to have the X11 client libraries installed, but no X server.
- ajtaylor 15y agoI've only recently (last week!) started using split buffers with vi, and it is a major game changer for me! I've read about NERDTree before, so I'm moving it up on my TODO list. If I may ask a newbie question, why do you use both tabs and split buffers? It seems like a little over kill, but perhaps it's because it allows you to easily switch between buffers w/o having to :b $file all the time? I haven't gone higher than 4 splits as the window sizes start getting too small.
- justanotheratom 15y agoI think what you are referring to as buffer is actually called a 'window' in vim. It is my understanding that a Tab can have Windows (created with veritical and horizontal splits), and Windows have buffers. You can switch buffers in the same Window, something I find very confusing.