Many answers make reference to a "paste buffer" or a "search buffer". Can someone provide a quick primer on what types of buffer there are? Are they interchangeable? Or is it something different?
I've edited your question, as you can refer to different concepts when you say "buffer", depending on context... Your original question was somewhat unclear IMHO ... I hope you agree with this, but feel free to change it back if you don't.– Martin TournoijFeb 4, 2015 at 16:48
The term "paste buffer" is often used (not just within the context of vim) to mean the clipboard or something similar. It's not necessarily the same use of "buffer" in the vim sense.– user72Feb 4, 2015 at 16:48
@Carpetsmoker thanks for the edit. Perhaps the multiple uses (and perhaps misuses) of the term buffer leads to my confusion.– drsFeb 4, 2015 at 16:55
@Carpetsmoker Actually, the term buffer is quite clearly defined in Vim. That people are misusing the term doesn't mean that there are actually multiple ways that it can be understood with respect to Vim.– jamessanFeb 4, 2015 at 16:56
Those posts are incorrectly using the term
buffer when they mean
As aharris88's answer shows, a buffer typically represents a file that is currently being edited. There are buffers that don't represent a file, but the common case is the representation of a file.
Registers, on the other hand, hold pieces of data for later use. An example that most people use on a frequent basis is the unnamed register (
"). This is the register that, by default, stores the last yank or delete and is the register used, by default, when pasting.
From the vim help:
Summary: A buffer is the in-memory text of a file. A window is a viewport on a buffer. A tab page is a collection of windows. A window is a viewport onto a buffer. You can use multiple windows on one buffer, or several windows on different buffers. A buffer is a file loaded into memory for editing. The original file remains unchanged until you write the buffer to the file. A buffer can be in one of three states: *active-buffer* active: The buffer is displayed in a window. If there is a file for this buffer, it has been read into the buffer. The buffer may have been modified since then and thus be different from the file. *hidden-buffer* hidden: The buffer is not displayed. If there is a file for this buffer, it has been read into the buffer. Otherwise it's the same as an active buffer, you just can't see it. *inactive-buffer* inactive: The buffer is not displayed and does not contain anything. Options for the buffer are remembered if the file was once loaded. It can contain marks from the |viminfo| file. But the buffer doesn't contain text.
You can access this with the command
You can get a list of your current buffers with
You can search through all your current buffers with the command
:bufdo which executes a command in all open buffers like this:
:bufdo %s/pattern/replace/ge | update