Linux vi command q vs q! — what is the difference?

Vi (or Vim) is the famous text editor on Linux operating system, it support the command q and q! (q followed by an exclamation mark), which look like almost the same, but is that true? what is the real difference between the two similar commands?

Here is a quick answer. The q command (:q) quit the current text file without saving, while the q! (:q!) forces a quit. If you opened a file in vi and made no changes to it, using q command will be enough. However, if you opened a file and already made a few changes to it, you have to use q!. This command will ignore all the changes made and allow you to do a forced quit.

Leave a Reply

Your email address will not be published. Required fields are marked *