For editing the program from the terminal window , we use the command

vim program.c

Then we can edit the program , how to save it after that and how to return to the terminal ? Which shortcut keys we use for that ? I used Ctrl+Z to get back to terminal, but with some additional information. But what is the right way to get back to the terminal ?

3 Answers 3


vim (aka vi) is a command-line text editor. You can open up an exiting file or creating a new one by executing

vi fileName.extension
  1. To start editing your file, you have to hit i from your keyboard to enter the INSERT mode.
  2. To save your file and exit, hit ESC from your keyboard and type :wq.
  3. To exit without saving, hit ESC from your keyboard and type :q!.

You may find more commands here!

  1. Press the key (to make sure you are in Normal mode).

  2. Type: :q! . This exits the editor, DISCARDING any changes you have made.

  3. Save the file with changes and exit Vim with: :wq

  4. :x :xit
    Like ":wq", but write only when changes have been made. When 'hidden' is set and there are more windows, the current buffer becomes hidden, after writing the file.

  5. ZZ
    Write current file, if modified, and quit (same as
    ":x"). (Note: If there are several windows for the current file, the file is written if it was modified and the window is closed).


To exit vim and save your changes, type :x or ZZ

The complete Vim help documents are found here: http://vimdoc.sourceforge.net/htmldoc/usr_toc.html

  • Thanks a lot! :) Jul 26, 2014 at 7:51
  • you're welcome. Be sure to vote up my answer and mark it as accepted if it solved your problem. :)
    – curiouskiwi
    Jul 26, 2014 at 7:53
  • :q also works. Use :wq to "save and quit". I don't know why this works, or what the difference is between this and :x and ZZ. Just the fact that there are at least three different ways to exit Vim indicates that it's not the most intuitive program to use. Jul 26, 2014 at 13:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .