How do I create a temporary scratch buffer for quick notes without saving a file?
Answer
:enew | setlocal buftype=nofile bufhidden=wipe noswapfile
Explanation
A scratch buffer is a temporary, unnamed buffer that exists only in memory — it won't prompt you to save when you close it and leaves no trace on disk. This is perfect for jotting down quick notes, pasting intermediate results, or experimenting with text transformations without cluttering your filesystem.
How it works
:enewopens a new empty buffer in the current windowsetlocal buftype=nofiletells Vim this buffer is not associated with any file on diskbufhidden=wipeautomatically destroys the buffer when it is no longer displayed in any windownoswapfileprevents Vim from creating a swap file for this buffer
Together, these options create a fully disposable buffer that behaves like a scratchpad.
Example
You're debugging and need a place to paste and compare some output. Run:
:enew | setlocal buftype=nofile bufhidden=wipe noswapfile
A blank buffer opens. Paste text into it, manipulate it freely, and when you're done, just close the window with :q — no "save file?" prompt, no leftover files.
For frequent use, add a mapping to your vimrc:
nnoremap <leader>s :enew<CR>:setlocal buftype=nofile bufhidden=wipe noswapfile<CR>
Now <leader>s instantly opens a scratch buffer.
Tips
- Open the scratch buffer in a split instead:
:vnew | setlocal buftype=nofile bufhidden=wipe noswapfilefor a vertical split, or:new | ...for a horizontal split - Use
bufhidden=hideinstead ofwipeif you want the buffer to persist in the background when you navigate away, so you can return to it with:bor:ls - You can name a scratch buffer for easier identification:
:file scratch-notesgives it a display name without creating a file - Scratch buffers are ideal for capturing the output of Ex commands:
:put =execute('ls')pastes the buffer list into the current buffer - Use
:read !commandin a scratch buffer to capture shell command output for inspection - If you accidentally close a scratch buffer, the contents are gone — there is no undo or recovery, so copy important text to a named register or file before closing