This is still an ongoing post, so some things may be incomplete.

Using Vim buffers

Closing buffers

Unload buffer [N] (default: current buffer) and delete it from the buffer list. If the buffer was changed, this fails, unless when [!] is specified, in which case changes are lost. The file remains unaffected.


Like |:bdelete|, but really delete the buffer.


NOTE: a word of caution: w does not stand for write but for wipeout.

Opening buffers

By default, Vim opens a new empty buffers when using the commands below, however, if specifying <filename> where filename is the name of the file, it opens a new buffer with the existing file. It <filename> does not exist, it creates an empty file.

<filename> is optional.

Create a split window with a unnamed or named buffer
:new <filename>
Will open one in the current window
:enew <filename>
Will open on in a vertically split window
:vnew <filename>
Will open one in a new tab
:tabnew <filename>

Vim splits

Vim allows you to split buffers so you can easily work looking at multiple files. Vim allows the user to split the file vertically or horizontally. By default, Vim duplicates the current buffer if no filename or buffer is specified.

Takes an optional filename and opens the file in a vertical split
:vs <filename>
:vertical <filename>
:vsp <filename>
Takes an optional filename and opens the file in a horizontal split
:sp <filename>
:split <filename>

Vim split height and resize ^^^^^^

Vim also allows you to specify a custom height for your buffer.

Specify the height of a buffer by prefixing a number
:10sp <filename>
:10vsp <filename>

To resize a current split, swap position, and move them to a tabview [[Vim tabs]], vim has a few key bindings to help out.

Table 1. Keyboard shortcurts to change split shapes and position
Shortcut Action

ctrl+w _

Max out the height of the currents split

ctrl+w |

Max out the width of the current split

ctrl+w =

Normalize all split sizes (handy when resizing the terminal)

ctrl+W R

Swap top/bottom or left/right split

ctrl+W T

Break out current window into a new tabview

ctrl+W o

Close every window in the current tabview but the current one