vimtricks.wiki Concise Vim tricks, one at a time.

How do I open a scratch split that is not listed and disappears when I close it?

Answer

:vnew | setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile

Explanation

For quick throwaway notes, command output cleanup, or temporary edits, a normal buffer is noisy: it appears in :ls, can prompt you to save, and may leave swap artifacts. A disposable scratch split gives you an isolated workspace that behaves like a temporary pad and cleans itself up when you close it.

How it works

  • :vnew opens a new vertical split with an empty buffer
  • setlocal buftype=nofile marks the buffer as not associated with a file
  • bufhidden=wipe removes the buffer completely when it is abandoned
  • nobuflisted keeps it out of the normal buffer list
  • noswapfile prevents swapfile creation for this temporary content

The result is ideal for short-lived tasks: collecting snippets during refactors, staging text before a substitution, or comparing fragments without polluting your normal buffer workflow.

Example

Before: two code windows, no temporary workspace.
After running the command: a new right-side split appears for scratch text.
Close that split, and the scratch buffer is wiped immediately.
:vnew | setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile

Tips

  • Add nowrap and nonumber if you want a cleaner note-taking pane
  • Map this command to a key if you use scratch buffers frequently
  • If you want the scratch buffer to survive window closes, use bufhidden=hide instead of wipe

Next

How do I restrict keyword completion to current buffer, windows, buffers, and tags for predictable results?