I was looking at the documentation for the 'complete' option, and I found it a bit confusing:

.   scan the current buffer ('wrapscan' is ignored)
w   scan buffers from other windows
b   scan other loaded buffers that are in the buffer list
u   scan the unloaded buffers that are in the buffer list
U   scan the buffers that are not in the buffer list
k   scan the files given with the 'dictionary' option
kspell  use the currently active spell checking |spell|
k{dict} scan the file {dict}.  Several "k" flags can be given, patterns are valid too.  For example:  
        :set cpt=k/usr/dict/*,k~/spanish
s   scan the files given with the 'thesaurus' option
s{tsr}  scan the file {tsr}.  Several "s" flags can be given, patterns are valid too.
i   scan current and included files
d   scan current and included files for defined name or macro |i_CTRL-X_CTRL-D|
]   tag completion
t   same as "]"

What is the difference between b, u and U? I thought as soon as you did either :e file/path or :badd file/path, everything gets "loaded" into memory for editing..


The situation with buffers is quite complicated. Use :ls (of :buffers) to inspect them.

There can be the following states:

  1. Active buffer --- both loaded into RAM and shown in (at least one) window. This is what you normally got after :e filename, :buffer N and so on. (flagged "a" by :ls; also when it's in active window, it's flagged by "%")

  2. Hidden buffer --- fully loaded but nowhere shown, except the buffer list. This is when you call bufload() to load a new buffer without showing it, or :hide an existing window/buffer, or do :quit while set hidden or setlocal bufhidden=hide etc. (flagged "h" by :ls)

  3. Unloaded buffer --- "the data stream" is unloaded from RAM, but all other stuff, such as local variables, options, bookmarks etc., is still preserved. This is what you get after :bunload, or (if set nohidden) when switching buffers by CTRL^, or do :quit! etc. (no special flag in :ls, except maybe #).

  4. Unlisted buffer --- this is just a special flag which is honoured by :ls command: unlisted buffers are not shown unless :ls! is specifed. (flagged "u" by :ls!)

In fact, any buffer has two independent flags: loaded and listed. "Loaded and nolisted" is a typical value for special buffers such as "help", so they are visible but not normally shown by :ls; "unloaded and nolisted" is set when a buffer is deleted.

  1. Deleted buffer --- this is both unloaded and unlisted buffer. "The data stream" is unloaded from RAM, and all buffer-local variables and options are erased. However, all local bookmarks are still intact alongside with "filename" and "buffer number". This is what you get after :bdelete. Also the same fate awaits for all "nofile" and "unnamed" buffers - they are not just unloaded but also deleted (also flagged "u" by :ls!, as they all are unlisted too).

  2. Wiped buffer --- this is a full extermination, no mercy, no trace in history. Done by :bwipeout.

  • For buffers, what are "local variables, options, bookmarks etc."? Could you provide a short explanation; or where I can read about this? A Google search gives vague results. – herophant Oct 12 '19 at 17:29
  • @herophant Please, forget about google and start to use the help system: :h buffer-variable, :h local-options and so on. – Matt Oct 12 '19 at 17:40
  • What does it mean exactly for a buffer's "data stream" to be unloaded from RAM? Since you can easily "re-load" an unloaded (but still listed) buffer at a moments notice with navigation commands like :bnext, :bprev, or :[N]b, a buffer being in an inactive state is effectively the same as a buffer in a hidden state. Are there some commands/operations you can perform on hidden buffers that you cannot perform on unloaded buffers? – Nicholas Cousar Sep 1 '20 at 3:37
  • 1
    @NicholasCousar Buffer = data + metadata. How much of metadata is freed or kept depends on buftype and operation. Only wipeout destroys everything including "name" and "number". – Matt Sep 1 '20 at 4:37

A buffer is listed if it's in the buffer list, you can see it in :h :buffers , you can refer to it with :h :buffer , :h :bnext , etc . It's controled by setting :h 'buflisted' .

A buffer is loaded if the corresponding file is loaded into memory.

Not all buffers should be listed, e.g. help type buffer is not listed, as no one wants to refer to it with :h :buffer .

Not all buffers should be loaded, as load is not free, it cost time and memory, it doesn't make sense to load a buffer that you might not use at all.

:e file/path create a listed and loaded buffer.

:badd file/path create a listed but not loaded buffer.

:args a b c d creates 4 buffers, all of them listed, but only a is loaded.

:bunload unload buffer.

:bdelete unload buffer, remove it in the buffer list, clear options, variables, maps, abbreviations.

:bwipe unload buffer, remove it in the buffer list, wipe everything.

You can check buffer info with :h getbufinfo() .

You can also check unlisted buffer with :buffers!.

  • What does :b file/path do? I'm guessing it edits file/path since it shows up on the terminal screen. Say you only have one window and you are editing file/path. You execute :b file/path2. Now you certainly have file/path2 loaded since you are editing it, but what happened to file/path? Has it been unloaded and that memory freed? – herophant Oct 12 '19 at 4:57
  • Original buffer (file/path) will be :h abondon , it's unloaded only if 'hidden' is off. – dedowsdi Oct 12 '19 at 5:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.