G go to last line
gg go to first line
a Append after cursor
i Insert before cursor
o Open line below
O Open line above
:r file Insert file after current line
substitute :%s/apple/pear/g
r replace a single character
R replace multiple characters untir ESC is pressed
copy a line yy or Y ("yank") and either p ("put below") or P ("put above").
delete a line dd
x delete a single character under cursor
exit and saveĀ :wq
exit without savint :q!
add something before every line
# If you want to edit the file in-place
sed -i -e 's/^/something_to_add_before_every_line/' file
# If you want to create a new file
sed -e 's/^/something_to_add_before_every_line/' file > file.new
replace comma separated line to new line with your own text
Here's the trick:
First, set your Vi(m) session to allow pattern matching with special characters (i.e.: newline). It's probably worth putting this line in your .vimrc or .exrc file:
:set magic
Next, do:
:s/,/,^M/g
To get the ^M character, type Ctrl + V and hit Enter. Under Windows, do Ctrl + Q, Enter. The only way I can remember these is by remembering how little sense they make:
A: What would be the worst control-character to use to represent a newline?
B: Either q (because it usually means "Quit") or v because it would be so easy to type Ctrl + C by mistake and kill the editor.
A: Make it so.