Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i get out of vi editor when esc won't work?

Tags:

vi

unix

cygwin

I am using vi editor for UNIX. Sometimes I am experiencing an issue with getting out of vi editor, where I go to press esc then type ":wq" or "q!" to quit, but it is not escaping. vi editor just enters weird symbols/characters and I can't get out. What do I do to escape and exit when esc won't escape?

like image 666
SendETHToThisAddress Avatar asked Apr 11 '17 02:04

SendETHToThisAddress


People also ask

How do I force quit in vi editor?

Press Esc to enter Command mode, and then type :wq to write and quit the file. The other, quicker option is to use the keyboard shortcut ZZ to write and quit. To the non-vi initiated, write means save, and quit means exit vi.

How do I exit Vim editor?

In Normal Mode , you can also press ZZ or ZQ to quit Vim. Where ZZ is the same as :x and ZQ is the same as :q! . Here, ZZ and ZQ are considered commands of Normal Mode while :x and :q! are Ex commands.


2 Answers

For me this worked: CTL + c (this is equal to ESC in your case) :wq! (to write save and quit) and then click enter

like image 128
Dhruval Patel Avatar answered Oct 24 '22 20:10

Dhruval Patel


There are few more commands for that apart from the one you are using

  1. Shift+zz to save (if modified )and exit
  2. :cq quit without writing

EDIT : I found some more commands that I just learned .

There are many ways to exit from vi editors, and you can use some of these commands to exit from other editors

  1. Press F2, this will drop you in Insert Mode, now press: q and hit enter
  2. another way is to press Ctrl + c or ctrl + z command to exit the vi editor forcefully.
  3. press ZZ (shift+z+z). it will save and exit.
  4. Ctrl + [ will also work like escape key.

the 3rd , and 6th command may or may not work on every system, as it depends on terminal's setting and system itself.

or you can do map certain keys to behave like escape, please refer this post , that will save you some keystrokes.

like image 20
Sushant Bhargav Avatar answered Oct 24 '22 18:10

Sushant Bhargav