Ubuntu – How to close vim from the command line

command linevim

I know this is more of a general linux question but w/e. So when I enter a program like vim in the command prompt it displays all the text in the file and I can edit it etc. But I can't figure out how to close or save the file and get back to the command prompt without killing the process. Any help is appreciated.

Best Answer

In vim there are 3 different modes:

  • Insert - allows typing and editing as normal
  • Visual - used for selecting copy/paste etc.
  • Normal - used for commands

To get back to Normal mode, you can always press esc.

Once you are at Normal mode Press : to begin your command (you'll see it appear in the bottom left). The following commands are related to quiting vim:

  • :q - quit if no changes were made
  • :q! - quit and destroy any changes made
  • :wq - write changes (save) and quit
  • :x - similar to :wq, only write the file if changes were made, then quit