Editing from the CLI with Vi (and gedit)

Using Vi

Open a file that requires editing from the terminal by running:

vi /some-directory/some-file

Use the arrow keys on your keyboard to navigate to the part of the line that needs to be edited and then type one of the following to start editing:

i - to insert text before the cursor
a - to insert text after the cursor

Edit the text as necessary.

To exit the editing mode press Esc.

The following commands can be used to change entire lines in a file. If in edit mode, first exit using Esc, then navigate to the line to be amended:

dd - deletes the entire line.
yy - copies the entire line into the buffer.
p - puts (pastes) the entire line from the buffer.
u - undoes the last action performed.

To save any changes and keep working in vi, type:

:w - to save the file

Finally, to quit vi, choose from the following:

:x - to save the file and exit
:q - to quit (exits back to terminal session) vi

Using gedit

Gedit is a more user-friendly and powerful editor for systems with a GUI.

To run Gedit, open a terminal session and type:

gedit

To run Gedit and open a file, type:

gedit /some-directory/some-file
Note: Add sudo / su for root permissions

Go back to the How-to Guides main page.

Search

Starter website

Offering small businesses and individual users the opportunity to have their own website on the internet, our 'starter websites' are available for only £150.

new site offer

To find out more and to see an example of the type of site offered, view our example starter website page.