The Basics of vi

General Information

Right then, vi. “Oh no! vi! That’s command based, can’t use that!” Oh come on, it’s not that difficult! Really… First, I shall explain a little about vi. vi (now mostly vim) is one of the oldest text editors for *nix. It can be found on many systems, both UNIX and Linux, and is usually the default editor. vim (VI iMproved) is beginning to take over from the older vi, but essentially, they function the same way.

Requirements

  1. Access to a server
  2. vi installed

vi

To open vi, you simply type vi at your prompt. To open a file with vi, just type vi followed by the filename, e.g. vi configure.txt.

When you’re in vi, you can’t just start typing; that’s where most people go wrong. When vi opens, it’s (usually) in command mode. You can press either a or i to take vi out of command mode, and you can start typing. Press Esc to re-enter command mode.

When in command mode, you can use the following commands:

:w
Write changes to disk and continue editing.
:wq
Write changes to disk and exit.
:q!
Exit without saving changes.
/text
Find text in the file.
G
Go to the end of the file.
nG
Go to line n.
x
Delete character that the cursor is on.
dd
Delete line (even if it wraps).
i
Insert text at cursor.
a
Insert text after cursor.

There are also two key bindings that you need to know for easy navigation of your file:

Ctrl+F
Forward one page.
Ctrl+B
Back one page.

That’s all you need to know! Have fun with vi, I promise it’s not too hard.

Speak Your Mind

*