A Q in the command mode of vi invokes ex. Any time you are
in ex, the command vi returns you to vi editor.
delete d Delete lines
move m Move lines
copy co Copy lines
t Copy lines (a synonym of co)
number(s) to edit.
You can specify line address in several ways:
* With explicit line numbers
* With symbols that help you specify line numbers relative
to your current position in the file.
* With search patterns as addresses that identify the lines
to be affected.
:3,18d Delete lines 3 through 18.
:160,224m23 Move lines 160 through 224 to follow line 23.
(Like delete and put in vi.)
:23,29co100 Copy lines 23 through 29 and put after line 100.
(Like yank and put in vi.)
:= Print the total number of lines.
:.= Print the line number of the current line.
:/pattern/= Print the line number of the first line
that matches pattern.
$ the last line of the file
% every line in the file
:.,$d
Delete from current line to end of file.
:20,.m$
Move from line 20 through the current line to the
end of the file
:%d
Delete all the lines in a file
:%t$
Copy all lines and place them at the end of the file
(making a consecutive duplicate).
In addtion to an absolute line address, you can specify
an address relative to the current line.
:.,.+20d
Delete from current line through the next 20 lines.
:226,$m.-2
Move lines 226 through the end of the file to two lines
above the current line.
:.,+20#
Display line numbers from the current line to 20 lines
above the current line.
:-,+t0
Copy three lines(the line above the cursor through
the line below the cursor) and put them at the top
of the file.
:read filename(:r filename)
inserts the contents of filename starting on the line
after the cursor position in the file.
:185r /home/tim/data
Read in file data and place it after line 185
:$r /home/tim/data
Place the read-in file at the end of the current file.
:0r /home/tim/data
Place the read-in file at the very beginning of the
current file.
:/pattern/r /home/tim/data
Place the read-in file in the current file, after the
line containing pattern.
convenient way to move text from one file to another. Named
buffers are not cleared when a new file is loaded into the
vi buffer with the :e command. Thus, by yanking or deleting
text from one file (into multiple named buffers if necessary), calling in a new file with :e, and putting the named
buffer(s) into the new file, you can transfer material
between files.
"f4yy
Yank four lines into buffer f.
:w
Save the file
:e letter
Enter the file letter with :e. Move the cursor to where
the copied text will be placed.
"fp
Place yanked text from named buffer f below the cursor.
Another way to move text from one file to another is to use
the ex commands :ya(yank) and :pu(put). These commands work
the same way as the equivalent vi commands y and p, but
they are used with ex's line-addressing capability and named
buffers.
[Exa]
:160,224ya a
yank lines 160 through 240 into buffer a.
Next move with :e to the file where you want to put these
lines. Place the cursor on the line where you want to put
the yanked lines. Then type:
:pu a
to put the contents of buffer a after current line.
in ex, the command vi returns you to vi editor.
{Editing with ex}
Full name AbbreviationMeaningdelete d Delete lines
move m Move lines
copy co Copy lines
t Copy lines (a synonym of co)
{Line Address}
For each ex editing command, you have to tell ex which linenumber(s) to edit.
You can specify line address in several ways:
* With explicit line numbers
* With symbols that help you specify line numbers relative
to your current position in the file.
* With search patterns as addresses that identify the lines
to be affected.
:3,18d Delete lines 3 through 18.
:160,224m23 Move lines 160 through 224 to follow line 23.
(Like delete and put in vi.)
:23,29co100 Copy lines 23 through 29 and put after line 100.
(Like yank and put in vi.)
:= Print the total number of lines.
:.= Print the line number of the current line.
:/pattern/= Print the line number of the first line
that matches pattern.
{Line Addressing Symbols}
. stands for the current line$ the last line of the file
% every line in the file
:.,$d
Delete from current line to end of file.
:20,.m$
Move from line 20 through the current line to the
end of the file
:%d
Delete all the lines in a file
:%t$
Copy all lines and place them at the end of the file
(making a consecutive duplicate).
In addtion to an absolute line address, you can specify
an address relative to the current line.
:.,.+20d
Delete from current line through the next 20 lines.
:226,$m.-2
Move lines 226 through the end of the file to two lines
above the current line.
:.,+20#
Display line numbers from the current line to 20 lines
above the current line.
:-,+t0
Copy three lines(the line above the cursor through
the line below the cursor) and put them at the top
of the file.
{copying a File into Another File}
:read filename(:r filename)
inserts the contents of filename starting on the line
after the cursor position in the file.
:185r /home/tim/data
Read in file data and place it after line 185
:$r /home/tim/data
Place the read-in file at the end of the current file.
:0r /home/tim/data
Place the read-in file at the very beginning of the
current file.
:/pattern/r /home/tim/data
Place the read-in file in the current file, after the
line containing pattern.
{Editing Multiple Files}
{Edits Between Files}
When you give a yank buffer a one-letter name, you have aconvenient way to move text from one file to another. Named
buffers are not cleared when a new file is loaded into the
vi buffer with the :e command. Thus, by yanking or deleting
text from one file (into multiple named buffers if necessary), calling in a new file with :e, and putting the named
buffer(s) into the new file, you can transfer material
between files.
"f4yy
Yank four lines into buffer f.
:w
Save the file
:e letter
Enter the file letter with :e. Move the cursor to where
the copied text will be placed.
"fp
Place yanked text from named buffer f below the cursor.
Another way to move text from one file to another is to use
the ex commands :ya(yank) and :pu(put). These commands work
the same way as the equivalent vi commands y and p, but
they are used with ex's line-addressing capability and named
buffers.
[Exa]
:160,224ya a
yank lines 160 through 240 into buffer a.
Next move with :e to the file where you want to put these
lines. Place the cursor on the line where you want to put
the yanked lines. Then type:
:pu a
to put the contents of buffer a after current line.