4.6 Editor -- vi |
vi
vi
text editor.
This can be a very good text editor for touch typists. The only
special key that is needed is the "escape" key. For a full
description of the vi
text editor look at the manual pages.
username@gort ~ $
cp ~cis137/flatpara.text .
(Did you notice the trailing period? You need it.)
If you are not using gortyou can get the file
with anonymous ftp from fromvi
.
username@gort ~ $
vi flatpara.text
:set number
to check your numbers.
In some versions of vi you will need to get out of
insert mode with the esc
key to move from one line to the next.
:
" command move to line 11. :11<cr>
.
t
" is a regular expression.
man
uses less
to help the user view the manual pages.
less
uses regular expressions for searching, like vi
.
So the "/
" and "?
" work for forward and backward searches.
You may need to look at the vi
manual pages.
You can use regular expressions
in many UNIX commands.
We will come back to regular expressions in several future labs.
?
"
is used to search backwards. An "N
" searches again, but in the
other direction.
:5,10s/\([aeiou]\)\([aeiou]\)/(\2\1)/gThis needs an explanation. The "
5,10s
" indicates what area of the file.
Between the first two forward slashes "/
" are two regular
expressions. They are marked off with "\(
" and "\)
".
They both specify vowels, [aeiou]
.
These regular expressions are referred to later
by "\1
" and "\2
".
The "g
" at the end is for global, all of the occurrences on a line.
You may want to copy this command from the web page.
vi
editor with the command "ZZ
" (Upper case).
This will save your file.
username@gort ~ $
lpr flatpara.text
your-name
Lab 4.6: vi
Part 2
TABER CIS137
Please turn your lab to Louis Taber or to Pima Community
College employee
in room A-115 of the Santa Rita Building.
Ask them to place it in the dark blue folder in
Louis Taber's mailbox.vi
Text EditorStarting | username@gort ~ $ vi file | start edit |
Stopping | ZZ | save edits and exit |
:wq | save edits and exit | |
:q! | abandon changes | |
:w | save changes & | |
continue editing | ||
Refresh screen | ^L | Clear and redraw screen |
Modes | ESC | forces Command mode |
ESC : | forces ed/ex mode | |
Cursor | use the cursor keys | if set up. |
k, j, l, h | up, down, right, left | |
0 | start of line | |
^ | start of line | |
$ | end of line | |
M | middle of screen | |
H | beginning of screen | |
L | Last line of screen | |
^U | up half a page | |
^D | down half pages | |
^F | forward full page | |
^B | back full page | |
line numberCR | go to specified line | |
Text | i | insert before |
a | append after | |
r | replace current character | |
x | delete current character | |
dd | delete line | |
p | put (insert) last delete | |
or yank | ||
P | put before current character | |
yy | yank to clipboard one line | |
Search | / textCR | look forward in text |
? textCR | look backwards in text | |
ed commands | : ed-commandCR | ex or ed commands |
:set number | show line numbers | |
:set nonumber | do not show line numbers | |
:setshow all | show all set-able items | |
setup file | .exrc | initialization file |
vi
":" commandsCommand format | In command mode type a ":" | |
A ":" and the cursor will be | ||
at the bottom of the screen | ||
waiting for a command. | ||
First 0, 1, or 2 decimal | ||
line addresses or . (current | ||
line) or $ (last line), then a | ||
command letter, usually lower | ||
case then, optional trailing | ||
arguments (and commands). | ||
Followed by a carriage return. | ||
Escaping from | The escape key | |
Stopping vi | :w | write file |
:q | exit - no write | |
:Q | abandon edits | |
Delete lines | :d | delete current line |
:2d | delete line 2 | |
:5,8dp | delete lines 5-8 and | |
print current line | ||
Un-do | :u | un-do last command |
:U | un-do last line | |
File commands | :f filename | sets file name |
:! shell-command | Insert shells output | |
Substitute | :s/ abc/ xyz/ | change, in the |
current line, the | ||
first abc to xyz. | ||
:1,$s/abc/xyz/g | change, all "abc "s | |
in file to "xyz " | ||
move text | :5,8m9 | move lines 5-8 to |
after line 9 | ||
copy text | :1,3t8 | copy lines 1-3 to |
after line 8 | ||
4.6 Editor -- vi |