Vi text editor tutorial
From NAS-Central Buffalo - The Linkstation Wiki
Based on work by nix and frontalot.
Originally by frontalot.
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.
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:
h - move to left l - move to right k - move up j - move down
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
yy - copy line(s). p - paste (previous delete or copy).
/<exp> - Search forward for <exp> (if no <exp> use previous). ?<exp> - Search backwards for <exp> (if no <exp> use previous.
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.
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.
Learning the vi Editor WikiMedia Wikibook
Mastering the vi Editor University of Hawaii at Manoa College of Engineering
An Introduction to Display Editing with Vi From the father of vi, William “Bill” Joy. Partly very dated.