Exit neon sign on brick wall background

How to exit from VIM and the most popular VIM shortcuts

If you are reading this article then you are in trouble. You wanted to edit a file using vim editor but got stuck in it. Stop panicking and wait with re-installing the OS and starting all from scratch – in this article I will show you how to exit a vim trap.

google search with request "how to quit vim"
Vim is the second hardest thing to quit after smoking

Exit VIM editor using key combinations

Vim editor is tricky for beginners, but when you learn right key combinations using VIM becomes easy. Here are most popular key combinations to quit vim.

Exit vim saving changes

To exit vim with saving changes press Esc key to exit editing mode, then hold down Shift and press colon key (:). Then enter “wq” and press Enter. Here “w” stands for write and “q” stands for “quit”. On US keyboards the colon : is the same key as semicolon ;, located right of the letter “L” key.


Exit vim without saving changes

To exit vim without saving changes hold down Shift and press the colon key (:). Then enter “q!” and press Enter.

exit vim without saving changes
exit vim saving no changes

Save changes without existing VIM editor

To save changes without exiting vim hold down Shift and press the colon key (:). Then enter “w” and press Enter.


Getting proficient in VIM

Now when I covered the basics of exiting Vim and saving changes lets proceed to some additional useful Vim shortcuts and features to enhance your proficiency.

Starting VIM to edit the file

Usually developers launch vim to edit the file using command:

vim filename

If the file is missing it will be created. You can specify multiple files to edit:

vim file1 file2 file3

To open file on specific line you can add +[num] after the vim command. For example to open file on line 127 enter:

vim filename +127

Once you’ve entered Vim, navigating efficiently is key. Here are some popular shortcuts:

  • Moving the Cursor:
    • Use the arrow keys to move in the respective directions (up, down, left, right).
    • Alternatively, employ the h, j, k, and l keys for left, down, up, and right movements, respectively.
  • Word Navigation:
    • Move the cursor to the beginning of the next word with w.
    • Navigate to the end of the current word using e.
    • Jump to the beginning of the previous word with b.
  • Navigating Lines:
    • Go to the start of the line by pressing 0.
    • Move to the end of the line with $.

Editing Text in VIM

Once you’ve reached the desired location, these shortcuts will aid in text manipulation:

  • Entering Insert Mode:
    • Press i to enter insert mode before the cursor.
    • Use I to start inserting at the beginning of the line.
    • Employ a to append after the cursor.
    • A allows appending at the end of the line.
  • Deleting Text:
    • Delete the character under the cursor with x.
    • Erase the entire line with dd.
    • Cut (delete) the current line and enter insert mode with cc.
  • Copy and Paste:
    • Copy a line with yy.
    • Paste the copied line below the current line using p.
  • Undo and Redo:
    • Undo the last action with u.
    • Redo with Ctrl + r.

Searching in VIM

Efficient searching is crucial. Here are some search-related shortcuts:

  • Searching for Text:
    • Initiate a search with /, followed by the desired term.
    • Use n to jump to the next occurrence and N to go to the previous one.
  • Replacing Text:
    • Substitute the current word with a new one using :s/old/new/g.

Exiting Vim

I have already covered the basics in the beginning, but here are a few more options:

  • Save and Quit All:
    • To save all changes and quit multiple files simultaneously, use :wa and :qa.
  • Exiting Without Saving:
    • If you want to exit Vim without saving any changes made in any of the files, :qa! will do the trick.


Remember, mastering Vim takes time and practice. The more you use it, the more comfortable and powerful it becomes. Happy editing!

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.