save a file with sudo vim

Asked by KPatrick

This may seem like a ridiculously simple question, however:

When editing a config file or some other file using the command
sudo vim /etc/wherever/you/put/it

how do you save the edited information and return to the command line portion of the terminal.

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu gnome-terminal Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Cesare Tirabassi (norsetto) said :
#1

Yes, vim is a strange animal :-)

In Normal mode, type : (that's a colon) to get to the vi command-line. Your cursor will be placed at the bottom of the screen after a colon. The following commands are used on the command-line to save the file and quit the program.
w Write (Save)
q Quit (Close)
wq Write and Quit. (Save and Close)
q! Force Quit (Close without saving changes)

Revision history for this message
Cesare Tirabassi (norsetto) said :
#2

Just as an afterthought, you may consider using nano. Still a console application but a tad bit more user-friendly.

Can you help with this problem?

Provide an answer of your own, or ask KPatrick for more information if necessary.

To post a message you must log in.