The Modeling Center workstations offer several ASCII text editors for working with input and data files: kedit, gedit, vi and vim.
vi is a line editor, meaning that its functions normally are executed line by line or word by word. Vim is a somewhat improved version of vi. Both operate in two modes: command and edit. Some edit functions can be carried out within command mode. All of the commands below work in both editors.
The following commands can be issued in command mode; type the colon to enter command mode, type the command, and press enter.
Command | Action | Comments |
---|---|---|
:q | Leave vi | :q! Insist on leaving |
:w 'fname' | writes the current file to disk as 'fname' | if a file of that name already exists, it will be overwritten |
:lnumber1, lnumber2 w 'fname' | writes the portion of the current file from linenumber1 to linenumber2 to 'fname' | :set nu to see line numbers |
:x | save and quit | :wq does the same thing |
These commands are not prefaced with a colon. They allow movement of the cursor within a file for viewing or to reach the point where editing is to begin.
Command | Action |
---|---|
- (dash) or <up arrow> | up a line |
<> or <down arrow> | down a line |
<backspace> or <left arrow> |
left a character |
<spacebar> or <right arrow> |
right a character |
$ | to end of line |
^ | to beginning of line |
H | to top of screen |
L | to bottom of screen |
M | to middle of screen |
<Ctrl>D | down a half page |
<Ctrl> U | up a half page |
<Ctrl> F | down a whole page |
<Ctrl> B | up a whole page |
'lnumber' G | to a specific line ('lnumber' is a numeral) |
:set nu | display the line numbers |
G | go to the end of the file |
/'text' | search for 'text', forward in file |
?'text' | search for 'text', backward in file |
n | search for next instance of text found |
N | go back to previous instance of text found |
A few editing commands can be used without entering insert mode:
Command | Action | Comments |
---|---|---|
x | delete character under cursor | |
nx | deletes n characters | n is a numeral |
dd | delete current line | |
ndd | deletes n lines | n is a numeral |
p | enters most recently dd'd text following cursor | = paste after cursor |
P | pastes in front of cursor | |
yy | yank; copies line to paste buffer | paste with p or P |
O <Esc> | insert blank line above cursor | |
o <Esc> | insert blank line below cursor | |
r 'newchar' | replace character at cursor with 'newchar' | i.e., overtype one character |
R 'newchars' | replace several characters | i.e., overtype multiple characters |
:r 'fname' | inserts file 'fname' in current file at the cursor | 'fname' must be a text file |
All replace commands put vi in insert mode; type <esc> to return to command mode. | ||
u | undo most recent change | |
. (period) | repeat last command |
Putting vi into insert mode causes it to behave more or less like a standard ASCII text editor. Once insert mode is entered, vi remains in insert mode until <esc> is pressed; commands from command mode are not executed, but rather entered as text, so be watchful.
Command | Action | Comments |
---|---|---|
i | enter insert mode | text fills left of cursor |
a | enter insert mode | text fills right of cursor |
I | insert text at beginning of line | |
A | insert text at end of line | |
<Esc> | exit insert mode |