The Vim editor uses the term "buffer" to describe the file being edited. In fact, the buffer is a copy of the file you edit. After you modify the buffer, write the contents of the buffer into the file. The buffer not only stores the contents of the file, but also stores all the tags, settings, and other things related to the edited file.
Simple Application Server
USD1.00 New User Coupon
* Only 3,000 coupons available.
* Each new user can only get one coupon(except users from distributors).
* The coupon is valid for 30 days from the date of receipt.
Hidden buffer zone
Suppose you are editing file one.txt and you want to edit file two.txt at the same time. You could have simply used ":edit
"two.txt", but since you have modified one.txt, it is useless to do so. And you don't want to save one.txt at this time. Vim can solve this problem for you:
:hide edit two.txt
The buffer "one.txt" disappears from the screen, but Vim still knows that you are editing this buffer, so it retains its modified text. Such a buffer is called a hidden buffer: the buffer stores text, but you cannot see it.
The parameter of the command ":hide" is another command. It makes that command behave as if the'hidden' option has been set. You can also set the'hidden' option without the ":hide" command. Its function is that when leaving any buffer, the buffer becomes hidden.
Be careful! When your hidden buffer has been changed, never exit Vim before all the buffers are saved.
Non-activated buffer zone
Once a buffer is used, Vim remembers some information about the buffer. Even if it is neither displayed in the window nor hidden buffer, it is still on the buffer list. Such a buffer is called an inactive buffer. Generally speaking,
Activate display in the window and load text
Hidden Do not display in the window, but load the text
Inactive Not displayed in the window, no text loaded
Inactive buffers will not be forgotten, because Vim saves information about them, such as tags. And remembering the file name has the advantage that you can read the file name you edited and edit them again.
List of buffer areas
You can view the buffer list with this command:
:buffers
Another command with equivalent effect, although the meaning is not so clear, it saves much trouble when typing:
:ls
The output might look like this:
1 #h "help.txt" line 62
2 %a+ "usr_21.txt" line 1
3 "usr_toc.txt" line 1
The first column stores the buffer number. You can use it to edit files without typing the file name, see below.
Following the buffer number are some flags. Then there is the file name, and the line number where the cursor was last stayed.
The possible flags are as follows (from left to right):
u Unlisted buffer |unlisted-buffer|.
% Current buffer.
# Rotate the buffer.
a The buffer is activated, the buffer is loaded and displayed.
h Hide the buffer, the buffer is loaded but not displayed.
= Read only buffer.
-The buffer cannot be modified, the'modifiable' option is not set.
+ The buffer has been modified.
Editing buffer area
You can edit a buffer by specifying its buffer number instead of typing the file name:
:buffer 2
But the only way to know the buffer number is to consult the buffer list. If the buffer number is not used, you can use the file name, or part of it:
:buffer help
Vim will find the best match for the file name you type. If there is only one buffer that matches it, that buffer is selected. In this example, "help.txt" is selected. To open a buffer in a new window:
:sbuffer 3
This method also applies to file names.
List of buffer areas used
You can move between the buffer lists with these commands:
:bnext edit the next buffer
:bprevious edit the previous buffer
:bfirst edit the first buffer
:blast edit the last buffer
To delete a buffer from the buffer list, use this command:
:bdelete 3
Similarly, this command also applies to file names.
If you delete an active buffer (the buffer displayed in the window), you also close the window. If you delete the current buffer, you also close the current window. If it is the last window, Vim will find a buffer to edit. You cannot edit nothing!
Remarks:
Even after the buffer is deleted with the ":bdelete" command, Vim still remembers it. This buffer actually becomes an "out-of-list" buffer, and it no longer appears in the list reported by the ":buffers" command. However, the ":buffers!" command will still list buffers "out of the list" (yes, Vim can do everything). To make Vim completely forget a buffer, use the ":bwipe" command. See also the'buflisted' option.