Vim:Buffer
lastmod 2023-04-24created 2016-01-096 edits
Buffer list
Use :ls or :ls! to print the buffer list.
Indicators (chars in the same column are mutually exclusive):
| Flags | Brief | ||||
| u | an unlisted buffer (only displayed when ! is used) | ||||
| % | the buffer in the current window | ||||
| # | the alternate buffer for " | ||||
| a | an active buffer: it is loaded and visible | ||||
| h | a hidden buffer: It is loaded, but currently not displayed in a window hidden-buffer | ||||
| - | a buffer with 'modifiable' off | ||||
| = | a readonly buffer | ||||
| + | a modified buffer | ||||
| x | a buffer with read errors | ||||
Active buffer list
function TrimLeft(text)
return substitute(a:text, '^[ \t]*', '', '')
endfunction
function GetBuffersOutput()
redir => output
silent execute 'buffers'
redir END
return output
endfunction
function GetListedBuffer()
let result = []
for cursor in split(GetBuffersOutput(), '\n')
let result += [matchstr(TrimLeft(cursor), '^[0-9]*')]
endfor
" return a string list.
return result
endfunction
Then call :call GetListedBuffer().
Example
-
:ls: prints the buffer list. -
:ls!: prints the buffer list. (also prints unlisted buffers) -
:bufdo [COMMANDS]:bufdoruns command for all buffers. -
:bufdo bd: Close all buffer. -
:bd: closes the current buffer. (it remains as an unlisted buffer) -
:bw: completely removes the current buffer. -
:bd2: closes buffer 2. -
:1,100bd: closes buffers 1 through 100. -
:echo bufnr('%'): prints the number of the current buffer. -
:bnext: go to the next buffer. -
:bprevious: go to the previous buffer.