Saving Buffers

Vim can write buffer contents to files using the following command:

CommandActionPattern
:writewrite to a file:w[rite] [path/to/file]

No-Name Buffers

You might have noticed that when a file is loaded into a buffer, the buffer takes the name of the file. So what happens when an empty buffer is opened? In that case, the buffer is called a "no-name" buffer.

No-name buffers are just like any other buffers, and the content can be saved to a file or simply thrown away.

To save the content from a no-name buffer to a file, simply add a filename to the :write command:

:write /path/to/file

This saves the current buffer content into the specified path, then updates the buffer to reflect the filename.

Saving Ranges to Files

Although not particularly useful in most cases, it is still useful to note that ranges can be applied to saving files.

:5,9wq

For example, if we had a file with 10 lines of content and in which every line was modified in some way, we could choose to write only the changes on lines 5–9, by using the following command: