VI Quick Reference
Commands:
Text input mode:
'a' - appends
'A' - appends to end of line
'i' - inserts
'o' - inserts new line(below current)
'O' - inserts new line(above current)
'J' - put's next line after current line
<esc> - get out of text input mode
':r Filename' - include a file right there
change-case:
while connecting from a windows-NT machine to an indigo through
x-windows (X-Win32), am able to change the case of the current
character by 'page-up' & 'page-down' keys. ie: holding them down
changes the case of the whole line. What codes do this?
File Saving/Quitting
'ZZ' - save and exit
':w n' - write to the file n
':w>>n - append to the file n
':w!' - just save
':q!' - quits without saving no matter what!
'^G' - gives file stats(all)
Character Movement
'$' - end of line
'}' - end of paragraph
'^' - beginning of line
')' - end of sentance
'j' - down
'k' - up
'h' - left
'l' - right
':###' - go to line number ###
'L' - first character at bottom of screen
'G' - last character of last line of file
'H' - first character at top of screen
Text Deletion
'dw' - deletes current word
':d' - deletes 1 line(line your on)
'D' - deletes rest of line
':d#' - deletes # lines(including line your on)
'd <dir>' - deletes 1 char to h or l
'd#<dir>' - deletes # chrs to h or l
Search for or Replace Text
'/keyword' - search forward for keyword
'?keyword' - search backward for keyword
':s/old/new' - replaces the next old with new only
':g/\word1\>/s//word2/g'
- replaces all word1's with word2's
Undoing Mes-ups
':u' - undo latest command
Cut'n'Paste
'P' -put last deletion above cursor
'p' -put last deletion below cursor
'"zd} -delete to end of paragraph, into buffer z
'"ZdG' -append to end of file into buffer z(after paragraph)
'4G"zp' -put contents of buffer 'z' before line 4
Buffers
deleted text goes into buffer 1, all other buffers get shifted
down by 1. There are 9 buffers.
"1pu.u.u.u. -scans through buffers 1-5
Miscellaneous Commands:
o^:%s/^^[17i.^[a//^["tdd@t
-open a line & start it with ':%s/^', end that open,
insert 17 periods, close that insert, &delete just
formed line into buffer 't'. @t executes buffer 't',
removing 17 characters from the start of each line.
:set number
-add superficial line numbers to the screen
OPTIONS
!vi {edit last file edited}
vi file {edit file}
vi {newfile}
vi + file {go to last line in file}
vi +10 file {go to 10th line of the file}
vi +/pat file {go to first occurance of pat}