Useful commands in vi to save/quit

There are few commands one can use to save a file n
To save and quit: <esc>:wq
To save (if modified) and then quit, if not modified then does not save quit: <esc>:x (by jwood@opsource.net)
To save (if modified) and then quit, if not modified then does not save quit: <esc>ZZ (by boomslaang@hotmail.com)
To save and continue edititing: <esc>:w
To quit: <esc>:q (Note: You will be able to quit from vi if no changes were made in the file since opening the file or all changes have already been saved, if there changes in the file vi will display the following message “No write since last change..”)
To force quit without saving: <esc>:q!
To save with a different filename: <esc>:w <new filename path can be specified too> (It can be used incases when one doesn’t have permission to overwrite the file or directory is not writable by the user so using this option the changes made by the user can be saved with a different name in a different folder)

2 comments

  1. press [shift]+Press “Z” twice, to QUIT as it is.
    Means, if any changes are made to file, it will be saved(:wq!), if no changes its effective to (:q!)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.