Wiki

by yszheda

View project onGitHub

Tip 36: Track Open Files with the Buffer List

Return to the top: <<Practical Vim>>

Understand the Distinction Between Files and Buffers

  • buffer: in-memory representation of a file
  • Most Vim commands operate on buffers, but a few operate on files, including the :write, :update and :saveas commands.

Meet the Buffer List

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h :!
  • <C-^>: toggle between the current and alternate files

Use the Buffer List

  • :bprev: move backward
  • :bnext: move forward
  • :bfirst/:blast: jump to the start/end of the list
  • :buffer N

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h :b
  • :buffer {bufname}
  • :bufdo: execute an Ex command in all of the buffers

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h :bufdo

Create Mappings to Quickly Traverse Vim's Lists

nnoremap <silent> [b :bprevious<CR>
nnoremap <silent> ]b :bnext<CR>
nnoremap <silent> [B :bfirst<CR>
nnoremap <silent> [B :blast<CR>

Deleting Buffers

  • :bd[elete]
    :bdelete N1 N2 N3
    :N,M bdelete