Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop Vim from saving a file if content has not changed

Tags:

vim

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.

like image 829
tshepang Avatar asked Feb 12 '13 13:02

tshepang


People also ask

Do not save and exit vim?

If you made some changes and would like to keep them, type :wq and press Enter / return. If you made some changes and would rather discard them, type :q! and press Enter / return.

How do we save and quit for all active tabs vim?

It's possible to suffix a[ll] for a number of Vim command-line commands (i.e. type : when in normal mode), include: :wa - save all tabs / unsaved buffers. :xa / :wqa - save all tabs / unsaved buffers and exit Vim. :qa - exit vim (will warn if unsaved buffers exist)

How do I save and quit in vi editor?

To save a file, you must first be in Command mode. Press Esc to enter Command mode, and then type :wq to write and quit the file. The other, quicker option is to use the keyboard shortcut ZZ to write and quit. In Vi, write means save, and quit means exit.


1 Answers

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.

like image 84
Prince Goulash Avatar answered Oct 21 '22 05:10

Prince Goulash