Both :file and :saveas seem to change the name of the buffer without writing. What's the difference between them? Also, in scratch buffers, :saveas seems to cause an error while :file does not. I included the relevant help sections below, but need some help making sense of them.

CTRL-G    or        *CTRL-G* *:f* *:fi* *:file*    
:f[ile][!] {name} Sets the current file name to {name}.  The optional !
      avoids truncating the message, as with |:file|.
      If the buffer did have a name, that name becomes the
      |alternate-file| name.  An unlisted buffer is created
      to hold the old name.

:sav[eas][!] [++opt] {file}
      Save the current buffer under the name {file} and set
      the filename of the current buffer to {file}.  The
      previous name is used for the alternate file name.
      The [!] is needed to overwrite an existing file.
      When 'filetype' is empty filetype detection is done
      with the new name, before the file is written.
      When the write was successful 'readonly' is reset.
      {not in Vi}

2 Answers 2


:saveas does write to files, after all the help says: "Save the current buffer under the name {file}". Note also how it says that ! is needed to overwrite an existing file. You wouldn't need to talk about overwriting if writing wasn't involved.

Also, note the message from a successful saveas command:

"bar" [New] 364L, 1060C written

:saveas is not going to work in a scratch buffer. A scratch buffer is a temporary buffer, that is not associated with a file and therefore cannot be saved. Instead they are discarded without warning, when vim is exited.

If you would like to know more:

:h special-buffers

:h buftype

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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