Using vi

vi is a text editor originally developed for UNIX but now included with Linux distributions and macOS.

It will take a little while to memorise some of the vi commands, but stick with it. Learning vi will greatly speed up simple file edits both for your local dev environment (if you are on a mac) and on your Linux server.

Its strength lies in being able to make quick edits to files without having to load big IDEs

vi is a modal editor with two modes, normal mode and insert mode. In normal mode key presses are interpreted as commands. In insert mode, text in the file can be manipulated.

To change between the two modes use press


to switch to insert mode then


to move back to normal mode.

Here are some more useful vi commands that will make editing files on Linux quick and easy:

Normal Mode

G – Move cursor to the end of the file
1G – Move cursor back to the beginning of the file
dd – delete line
3dd – delete 3 lines (substitute 3 for any number of lines)
:q – Quit, i.e. close the file
:qs – Quit and save
:q! – Quit and do not save

Insert mode

i – insert text before cursor
a – insert text after cursor
A – insert text at the end of the line
Esc – Leave insert mode