Vi text editor tutorial

This article
Based on work by nix and frontalot.
Originally by frontalot.
at Linkstationwiki.org

Note

OpenLink’s vi is actually the busybox vi clone. Experienced vi users will recognize that the busybox vi lacks quite a number of vi commands and that the command interpreter does not understand all command syntax variants. The most “dangerous” issue is the absence of vi’s crash recovery feature. Neverthless the busybox vi is functional and suitable for the Linkstation.

Introduction

vi is a command-oriented text editor. There are two modes in vi, COMMAND mode and INSERT mode.

COMMAND mode allows you move around inside your file quickly. When you first start vi, you are in command mode; otherwise, press ‹Esc› to get back to command mode. INSERT mode allows you to create and modify text in your file. Press i, a, or o (see below) to get to insert mode. Press ‹Esc› to get back to command mode.

Here are a few basic vi commands you can use while in command mode:

Navigation:

h - move to left
l - move to right
k - move up
j - move down

Editing Text:

x - erase a character
dd - delete a line
D - delete from cursor to end of line.
i - enter insert mode (insert before cursor)
a - enter insert mode (append after cursor)
A - enter insert mode (append to end of line)
o - enter insert mode (open line below)
J - join next line to current
U - undo changes to line
. - Repeat last edit

Many of the above can be preceded by a number, e.g. 5x (delete 5 characters, 12yy copy 12 lines, etc).

To EXIT the vi editor, either:

change into command mode (by typing <Esc> if necessary), then type : (colon). The colon will appear at the bottom of your screen; to save and quit, type in wq and press ‹Enter›; to quit without saving type q! and press ‹Enter›.

direct from visual mode type ZZ.

Weblinks

The following tutorials all assume you have a proper version of vi installed. If things don’t work as described in a tutorial, it might be because of limitations with the busybox version of vi.