tshepang
tshepang

Reputation: 12459

Stop Vim from saving a file if content has not changed

In GUI text editors I've seen, when text has not changed (or has changed and been reverted to its original state), the Save option is greyed out to indicate so.

For something similar, can Vim disable saving a file in such a case? That is, doing the :w would not actually change the mtime of the file.

Upvotes: 19

Views: 2500

Answers (2)

Felipe Alvarez
Felipe Alvarez

Reputation: 3898

WRITING WITH MULTIPLE BUFFERS               *buffer-write*


                            *:wa* *:wall*
:wa[ll]         Write all changed buffers.  Buffers without a file
            name or which are readonly are not written. {not in
            Vi}

:wa[ll]!        Write all changed buffers, even the ones that are
            readonly.  Buffers without a file name are not
            written. {not in Vi}

:wa will save all changed files

:xa will save all changed files, and then quit vim.

Upvotes: 0

Prince Goulash
Prince Goulash

Reputation: 15715

You can use the :update command (:up for short) which writes the file only if the buffer has been modified. If you felt strongly you could add an update option to gvim's File menu, but maybe the Ex command is sufficient.

Upvotes: 28

Related Questions