I can't save changes after editing

sudo vi /etc/network/interfaces

Text before editing:

auto lo
iface lo inet ...

Edited to:

auto eth0
iface eth0 inet dhcp

What key combination or sequence must I press to save this?

  • 7
    If you are not comfortable with editing files in terminal based editors like vi or vim, I would recommend using graphical based editor like gedit to open them. Replace sudo vi with gksu gedit.
    – Aditya
    Feb 8, 2013 at 15:15
  • 5
    Or use sudo nano Its also command line but a lot more intuitive than vi. Oct 19, 2013 at 9:46

4 Answers 4


You're probably in editing/insert mode. You need to type the following sequence :

  1. Esc, to quit edit mode and fallback to command mode ;
  2. :+w+q, start with a : (colon) then press w and finally q to write and quit (or just :w to write without quitting)
  3. then press Enter to valid.
  • Sometimes got bugs- pressed control + q Jun 9, 2021 at 20:08

I usually press ESC and then hold Shift and press z twice. Just like you would like to type two capital Z letters in word editor :) That saves your document and closes your editor.

  • 4
    Oh man, shift and double z, what was the design logic behind that I wonder, "what's the least intuitive command we can create?", ubuntu sometimes pisses me off like mad
    – S..
    May 25, 2014 at 11:10
  • 4
    @Sam, I just wanted to nitpick that vi has nothing in particular to do with ubuntu. Ubuntu was first released on 2004, while vi was created by Bill Joy around 1976, inspired by ed (dating back to 1971). This means that the shortcuts in vi predate those in almost any other still commonly used utility today. In a sort of coincidence, the first version of emacs, which has completely different weird shortcuts, was also released on 1976. Standardization efforts came much much later.
    – yoniLavi
    Nov 21, 2014 at 2:00
  • Wow thanks for the info @yoniLavi , my points is still the same though, so hopefully standardization efforts keep advancing.. :)
    – S..
    Nov 21, 2014 at 9:12
  • @Sam, vi keybindings are actually a lot more standard than you think; they're virtually ubiquitous. Practically any program can be made to emulate vi keybindings. Even the default Gmail keybindings are obviously (to a Vim user) based off of vi keybindings.
    – Wildcard
    Dec 21, 2016 at 0:27
  • what about esc key does not work? Insert mode, just stopped.
    – creator
    Mar 10, 2018 at 7:07

Check whether you have administrative (root) privileges to edit the file. use this command


If the result is not "root", then you are not supposed to edit the file.

To login as root user, use the below command

sudo su



Edit the file,

vi /etc/network/interfeces

After the changes, save the file using

  1. Press Esc to change the mode
  2. :x to save and quit the file

Thats all


this question was answered a long time ago, but in case it comes up in search engines again, this link is a nice vim cheatsheet that you might want to bookmark if you use vim a lot.

By the way, You can use :wq to save and exit the file ( you should first press esc key to exit insert or replace mode and then press commands ) and use :q! to exit without saving.

You must log in to answer this question.

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