Wednesday 21 February 2007

How to use Vi in Terminal

In my quest to get fedora core 6 working correctly on my MacBook. I realized that I would at some point have to create .conf files etc. and to do this I would have to use Vi. Which I found myself can be a bit annoying when trying to find a input to create or modify a file.


Vi has 2 modes, command mode and insert mode.

1. command mode
Here are some of the basic command to get you through the editor:

h = move the cursor 1 character left
j = move the cursor 1 character down
k = move the cursor 1 character up
l = move the cursor 1 character right
i = enter insert mode before cursor
I = enter insert mode at begging of line
a = enter insert mode after the cursor
A = enter insert mode at the end of current line
o = create a new line below current line and enter insert mode
O = create a new line above current line and enter insert mode
/string = searches for the first instance of string
n = next occurrence
$ = move the cursor to end of line
:x = move cursor to line x
u = undo
r = replace single character
R = like insert mode but replaces characters until [Esc] is hit
x = delete single character
dw = delete word
dd = delete line
D = delete rest of line after cursor
yy = copy line
p = paste
g = returns line number
:w = save file
:q! = quit without saving
:wq or ZZ = save and quit

2. Insert/replace mode mode
You can type just as you would in any editor.
To quit and return to command mode press [Esc]

No comments: