Sometimes I see a window open with name scratch.

I know it is some kind of temporary buffer/window.

How can I crate one?

:h scratch returns nothing.


It is probably a scratch buffer, which can be named. From the help:


Contains text that can be discarded at any time. It is kept when closing the window, it must be deleted explicitly. Settings: >

      :setlocal buftype=nofile
      :setlocal bufhidden=hide
      :setlocal noswapfile
  The buffer name can be used to identify the buffer, if you give it a meaningful name.

This can be found in :help special-buffers.

  • 1
    which :h command used to access this help? – wizzup Feb 8 '17 at 13:33
  • 2
    :h buffer, then read down through "Special kinds of buffers". You were on the right track. – wbogacz Feb 8 '17 at 13:36

I remember a vim tip (which has been migrated to vim.wikia) on the subject.

The latest version of the function I use to create scratch buffers also sets:

  • 'buflisted' to false
  • 'readonly'

(From my VimL library plugin: lh-vim-lib)

function! lh#buffer#scratch(bname, where) abort
    set modifiable
    " The next function takes care of working around this damn E36
    call lh#window#create_window_with(a:where.' sp '.escape(substitute(a:bname, '\*', '...', 'g'), '#%'))
  catch /.*/
    throw "Can't open a buffer named '".a:bname."'!"
  setlocal bt=nofile bh=wipe nobl noswf ro
  return bufnr('%')

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.