vi file.txt
vim file.txt
####
gg goes to top of file. NNgg goes to line NN. NN means an integer OK?
G goes to bottom of file
dd deletes current line under cursor. NNdd deletes NN lines
yy 'yanks' ie copies the current line and NNyy yanks NN lines.
p pastes the current buffer at the end of the line the cursor is on.
Both dd and yy fill the buffer.
^ goes to begining of line like REs. Literal ^ not control BTW
$ goes to end of line like REs
u undo, NNu undo last NN changes.
Ctrl+r redo, NNCtrl+r redo last NN undo-s
x deletes char under cursor. NNx deletes NN chars to RHS of cursor.
r type r and the next char you type will replace the char under the cursor.
handy for s/'/"/ and the like.
J Joins the cursor line to the line below ie remove \n from cur line.
Note j is nav J is join.....
Note Backspace will more you backwards (ie navigates but no deletion in nav mode) but
DEL deletes as normal (ie no navigation stuff disappears). GOK.
##
##
:w writes file
:w! writes file even if read only
:q quit
:q! quit and don't mess with me. ie if I have made changes
ignore them and exit with no write (good for f ups)
:wq write quit (usually what you want)
:wq! write quit don't question my wisdom!
There are also lots of neatish widgets, here's three
:shell gives you a shell to do stuff. type exit to return to vi.
:!command gives you a shell immediately below colon.
ie !./script while you are editing 'script' it will exec it.
hit enter to return to vi as prompted, else type more commands.....
:%perldo s/this/that/ execs that perl s///
##
##
a Insert after the current cursor pos
A Insert after the end of current line
i Insert before the current cursor pos
I Insert at the begining of the current line