LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to exit vi? (https://www.linuxquestions.org/questions/linux-general-1/how-to-exit-vi-19794/)

error_401 02-19-2012 06:17 AM

Just hitting the same problem today.

Logged in remotely to a server I need to edit a file on. Starting vi works, loads the file, editing is possible.

Unable to leave vi whatsoever. Something looks wrong with the key behaviour.
Hitting "ESC" produces a

Code:

^[
instead of the expected

Code:

:
so no way to leave vi and also no way of leaving the active ssh console :(

Any inputs on how to deal with that?

Workaround

How to get out of vi. (Careful, this is forcing something which could leave you with unwanted outcome! I assume no resonsability whatsoever!)

Open a second console window.
Open a second ssh connection to the affected host your stuck in vi
Do the following:

First list all processes. Find the affected vi process which should be pretty much at the bottom anyway with:
Code:

ps | more
and use the "space" bar to scroll pagewise through the process list.
Then use:
Code:

kill xxxx
where xxxx is the process number of the vi command in which you are stuck to kill the vi process. You should be back on the ssh prompt. Now you can normally exit the ssh shell on both consoles.

Nardu 12-09-2018 11:54 PM

use VIM instead
 
Hi All,

For the lost beginners that will reach this thread, here's a suggestion.

I far prefer vim to vi to edit files. Some are just personal preference, but the winning reason is as follows.
Once you have vim installed, there is a guided practice or exercise you could use to learn how to use the editor in cli.

In cli (as sudo, if applicable) just type vimtutor and return.

This vimtutor will show you the ropes around all of the yank/put (copy/paste) commenting out, searching and all basics controls.

berndbausch 12-10-2018 01:28 AM

Quote:

Originally Posted by lommer0 (Post 85412)
Btw, this kind of super-newbie information should maybe be put in man pages? maybe a section of the man dedicated to newbs? Just so that people might have some idea where to start...

this also applies to exiting man pages I figured out too... :-)

Man pages are reference documents, not necessarily meant to be introductions.

There is enough material available on vi and vim, though. For example this very official-looking https://www.linux.com/learn/vim-101-beginners-guide-vim, or several books (some free), tutorials and other programs directly on the vim site: https://www.vim.org/docs.php.

There is even a command named vimtutor. Not sure though if it exists on your distro.

YesItsMe 12-10-2018 03:23 AM

Quote:

Originally Posted by Nardu (Post 5935325)
For the lost beginners that will reach this thread, here's a suggestion.

I far prefer vim to vi to edit files.

That will not really help lost beginners, since Vim uses similar commands as vi, including the exit. But yes, once you're in vimtutor (which is basically Vim with a help file in a buffer), it will tell you how to get out. :)

ehartman 12-10-2018 07:30 AM

Quote:

Originally Posted by lommer0 (Post 85331)
Ok, I've been using linux on console only PC for a couple days now and one big thing is really bothering me...

How do I exit vi

For _real_ vi, use :x<enter> (save if needed and then exit), when you're using the improved vi (vim), ZZ (from visual mode) will do just the same (and it's one less keystroke).

emacs and joe I never used, so do not know.

YesItsMe 12-10-2018 07:46 AM

Quote:

Originally Posted by ehartman (Post 5935473)
emacs and joe I never used, so do not know.

Emacs: Ctrl+XC (or Ctrl+XS Ctrl+XC to save first).
Joe:
  • jpico mode: Ctrl+O (to save), Ctrl+X (to exit).
  • jmacs mode: See Emacs.
  • jstar mode: Ctrl+KX to save and exit, Ctrl+KQ to exit without any further actions.
  • joe mode: Ctrl+KX to save and exit, Ctrl+C to exit without any further actions.

DavidMcCann 12-10-2018 10:20 AM

My advice on using vi or emacs is "use nano!" — certainly for the non-professional.

ondoho 12-11-2018 02:04 AM

you're all aware that the OP is from 2002, right?


All times are GMT -5. The time now is 10:41 AM.