Step 6 of 6

11. Buffers

Deleting a buffer

If you like to keep your buffer list nice and tidy, you can use the :bd command to delete a buffer from the buffer list. :bd by itself will get rid of the current buffer, but just like the :b command, you can also specify a buffer number or a file path.

And don’t worry — if you try to delete a buffer that has unsaved changes, Vim will stop you from proceeding.

Work through the checklist below. Open all of the text files in the current directory with :args *.txt, then thin the list back out with :bd — once by name, and once from inside the buffer itself.

  1. Open every text file at once Vim loads all five files and lands in the first, a.txt — type :args *.txt and hit Enter.
  2. Delete bar.txt's buffer You can delete a buffer you're not even in — type :bd bar.txt and hit Enter.
  3. Delete the buffer you're in Plain :bd deletes the current buffer and drops you in one of the survivors — type :bd and hit Enter.
  4. Check what's left Two buffers down — type :ls, hit Enter, and hit Enter again to dismiss the list.
Open every text file at once Vim loads all five files and lands in the first, a.txt — type :args *.txt and hit Enter.

Next: Delete bar.txt's buffer

Loading editor…