Difference between revisions of "Vi text editor tutorial"

From NAS-Central Buffalo - The Linkstation Wiki
Jump to: navigation, search
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{Template:Articles}}
 +
''<font color=red><small>
 +
This article
 +
Based on work by nix and frontalot.
 +
Originally by frontalot.
 +
at Linkstationwiki.org
 +
</small></font>''<br>
 +
 
<h2>Note</h2>
 
<h2>Note</h2>
 
<p>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.</p>
 
<p>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.</p>
Line 10: Line 18:
 
<p>Here are a few basic vi commands you can use while in command mode:</p>
 
<p>Here are a few basic vi commands you can use while in command mode:</p>
  
 +
Navigation:
 
  h  - move to left
 
  h  - move to left
 
  l  - move to right
 
  l  - move to right
 
  k  - move up
 
  k  - move up
 
  j  - move down
 
  j  - move down
 +
 +
Editing Text:
 
  x  - erase a character
 
  x  - erase a character
 
  dd - delete a line
 
  dd - delete a line
 +
D  - delete from cursor to end of line.
 
  i  - enter insert mode (insert before cursor)
 
  i  - enter insert mode (insert before cursor)
 
  a  - enter insert mode (append after cursor)
 
  a  - enter insert mode (append after cursor)
 +
A  - enter insert mode (append to end of line)
 
  o  - enter insert mode (open line below)
 
  o  - enter insert mode (open line below)
 
  J  - join next line to current
 
  J  - join next line to current
 
  U  - undo changes to line
 
  U  - undo changes to line
 +
.  - Repeat last edit
  
<p>To EXIT the vi editor 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›.</p>
+
Copy/Paste:
 +
yy - copy line(s).
 +
p  - paste (previous delete or copy).
 +
 
 +
Searching:
 +
/<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).
 +
 
 +
<p>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.</p>
  
 
<h2>Weblinks</h2>
 
<h2>Weblinks</h2>
Line 34: Line 60:
  
 
[[Category:General]]
 
[[Category:General]]
 +
 +
[[Category:Development]]

Latest revision as of 15:34, 24 June 2007

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

Copy/Paste:

yy - copy line(s).
p  - paste (previous delete or copy).

Searching:

/<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:

  1. 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›.
  2. 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.

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.