Using Vi
What is Vi?
Vi (pronounced vee-eye) is a text editor available on Super Computing Wales and virtually all Linux and Unix based computers. It was originally developed by Bill Joy in 1976 while he was at the University of California, Berkeley. Vi was designed to run on remote terminals over very slow connections and is known as the “visual editor”. Vi is part of the Linux standard base so you can guarantee that it will be installed on other Linux systems you may have access to.
Using Vi
To use Vi on Super Computing Wales you must logon to a head node such as hawklogin.cf.ac.uk. You can only use it in terminal mode. To logon to Super Computing Wales you can use PuTTY. Please read the documentation before installing, and note that you can download PuTTY for free and install it on your computer.
Getting Started
To begin editing a new file type “vi” at the command prompt
Then type “i” to change to insert mode and begin typing
Then press the <Esc> key when you are done typing
Then type “:w path/to/file” and hit enter to save the file
Then type “:q” to quit vi
Starting Vi
Command | Description |
---|---|
vi | run vi |
vi myfile.txt | run vi and open myfile.txt |
vim | run vim |
vim /home/user/myfile.txt | run vim and open /home/user/myfile.txt |
Leaving Vi
Command | Description |
---|---|
ZZ | quit vi and write current file |
:q | quit vi |
:wq | write current file and quit |
:q! | quit vi and do not write current file |
File Operations
Command | Description |
---|---|
:e /home/user/myfile.txt | edit myfile.txt (tab completion works) |
:w /home/user/myfile.txt | write myfile.txt (tab completion works) |
:w | write open file |
Modes
Command | Description |
---|---|
return to command mode | |
i | change to insert mode before current cursor position |
a | change to insert mode after current cursor position |
o | change to insert mode but start a new line below current cursor |
Cursor Operations
Command | Description |
---|---|
[repeat]w | move forwards [repeat] words |
[repeat]b | move backwards [repeat] words |
^ | move to the beginning of the line |
0 | move to the beginning of the line |
[repeat]f | move forwards to the [repeat] instance of |
[repeat]F | move backwards to the [repeat] instance of |
[number]G | move to line [number] |
H | move to the home line (first line on the screen) |
M | move to the middle line (on the screen) |
L | move to the last line (on the screen) |
( | move backwards one sentence |
) | move forwards one sentence |
{ | move backwards one paragraph |
} | move forwards one paragraph |
Edit Operations
Command | Description |
---|---|
u | undo |
redo | |
[repeat]dw | delete (cut) [repeat] words |
[repeat]dd | delete (cut) [repeat] lines |
d$ | delete (cut) to end of line |
dG | delete (cut) to end of file |
[repeat]yw | yank (copy) [repeat] words |
[repeat]yy | yank (copy) [repeat] lines |
p | put (paste) |
Search and Replace
Command | Description |
---|---|
[repeat]/ | search forwards to the [repeat] instance of |
:s/ | search and replace the first instance of |
:s/ | search and replace all instances of |
:%s/ | search and replace all instances of |
Getting Help
:help
References
man vi – command line documentation
Learning the Vi and Vim Editors, Seventh Edition, http://openisbn.com/isbn/059652983X