Learn Vim at your own pace with my self-study Core Vim Course.

Learn more

Learn Vim at your own pace with my self-study Core Vim Course.

Working with buffers

#6

Run time:

Introducing the buffer list, and commands for switching between buffers. This episode also covers the concept of ‘hidden’ buffers, and shows how to deal with them.

Shownotes

Working with buffers

These commands show and navigate through the buffer list:

command action
:ls show the buffer list
:bn open the next buffer in the current window (cycles from the end of the list to the beginning).
:bp open the previous buffer in the current window (cycles from the start of the list to the end).
CTRL-^ switch to the alternate file

Dealing with hidden buffers

A buffer is marked as ‘hidden’ if it has unsaved changes, and it is not currently loaded in a window.

If you try and quit Vim while there are hidden buffers, you will raise an error: E162: No write since last change for buffer “a.txt”.

In this scenario, you can do any of the following:

command action
:w save the changes to a file
:e! restore the original file
:bd! forcibly remove the buffer from the buffer list, discarding any changes
:q! force Vim to quit, discarding changes to all modified buffers

By default, Vim makes it difficult to create hidden buffers. To make Vim more liberal about hidden buffers, put the following in your .vimrc:

set hidden
Comments

Level-up your Vim

Training

Boost your productivity with a Vim training class. Join a public class, or book a private session for your team.

Drew hosted a private Vim session for the shopify team that was one of the best workshops I have ever attended.

John Duff, Director of Engineering at Shopify

Publications

Make yourself a faster and more efficient developer with the help of these publications, including Practical Vim (Pragmatic Bookshelf 2012), which has over 50 five-star reviews on Amazon.

After reading it, I've switched to vim as my default editor on a daily basis with no regrets. ★★★★★

Javier Collado

Learn to use Vim efficiently in your Ruby projects

In association with thoughtbot, one of the most well respected Rails consultancies in the world, I've produced a series of screencasts on how to make navigating your Ruby projects with Vim ultra-efficient. Along the way, you’ll also learn how to make Ruby blocks a first-class text object in Vim. This lets you edit Ruby code at a higher level of abstraction. Available to buy from thoughtbot..