2

To input vim and enter command mode ,then to input vs,two windows created.
enter image description here

Now to input w test.html,why file names in left and right windows are same--test.html?
I just named the file in left window as test.html, why the file in right window named as test.html too?

4

When you did :vs you split the window on the current buffer, but did not create a new buffer; instead you have two windows viewing the same original buffer.

When you did :w test.html, you caused the buffer to take a new name. Because both windows are showing the same buffer, both windows show the new name of the buffer, namely test.html.

There is a good read at :help windows-intro, which starts thusly:

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.

I'd organize it a bit more in order: Vim has tabs. Tabs have windows. Windows are views of a buffer. A buffer is the file contents in memory, typically tied to a filename.

The :vs command is the same as :vertical split; and the documentation for :split calls out that "The result is two viewports on the same file", unless you also specify a new file name, in which case the new file is opened in the newly created window. (see :help :vs and :help :split for more details)

You may also notice that, when both windows' viewports show the same region of the buffer, you can see changes to both at the same time (try going into insert mode and type some text).

Creating a separate buffer when splitting

I think what you expected was that, after splitting, you had 2 different buffers. You can either specify a filename after the :vs command (like :vs myfile.html). If the file exists, it will be opened. If not, you get a blank buffer that will create the file once saved.

To create a new window with a new unnamed buffer, try :vertical new (or :vne for short) instead of :vs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.