Kvass
Kvass

Reputation: 8444

Vim - permit quitting with new modified files

The default behavior of Vim seems to be that :q will raise an error if the buffer is modified, and :q! will quit the buffer even if modified. I would like to change the behavior of :q so it will only raise an error if the buffer is modified AND is associated with an existing file. In other words, if a new buffer was created (e.g. by :new or by :e nonexistentfile.txt) and was modified without being written, I want :q to discard the changes.

Upvotes: 0

Views: 76

Answers (2)

robenkleene
robenkleene

Reputation: 597

Automatically make buffers with no backing files not prompt to save (and buffers with backing files will continue to prompt):

augroup nofilename_nofile
  autocmd!
  " Don't prompt for saving buffers with no file
  autocmd BufEnter * if eval('@%') == '' && &buftype == '' | setlocal buftype=nofile | end
augroup END

Upvotes: 0

Peter Rincker
Peter Rincker

Reputation: 45177

I think what you want is to create scratch buffers.

command! Scratch new | setlocal buftype=nofile bufhidden=hide noswapfile

Just issue :Scatch to create a scratch buffer

Upvotes: 2

Related Questions