VI Quick Reference Guide ------------------------ GETTING STARTED vi filename - normal mode vedit filename - user friendly edit esc - return to command mode INSERTING SAVING AND QUITING o - insert a line after cursor O - insert a line before cursor ZZ - save and exit i - insert text at cursor :w - save without exiting a - insert text after cursor :w! - save write protected file I - insert text at start of line :q - quit editor A or $a - insert text at eol :q! - quit without saving CURSOR MOVEMENT DELETING k dd - delete current line ^ x - delete char at cursor h < > l X - delete char before cursor v dw - delete word j D or d$ - delete from cursor to eol REPLACING / CHANGING R - replace till eol r - replace one character C - change all text after cursor cw - change a word MOVING ABOUT c$ - change from cursor to EOL cG - change from cursor to EOF f - page forward b - page back d - 1/2 page forward MOVING TEXT u - 1/2 page back w - next word To move n lines of text from A to B b - previous word 1. move cursor to A $ - end of line 2. ndd - delete n lines ^ - start of line (shift 6) 3. move cursor to B G - go to end of file 4. P - pull text in after cursor 1G - go to beginning of file p - pull text in before cursor nG - go to nth line g - show position in file (,( next, previous sentence ^D - Goes half page down ]],[[ next, previous section ^U - Goes half page up },{ next, previous paragraph ^F - Goes one page DOWN % goto matching parenthesis () {} [] ^B - Goes one page UP SEARCHING COPING TEXT /abc - search for string "abc" To copy n lines of text from A to B n - find next occurrence 1. move cursor to A N - find previous occurrence 2. nyy - yank n lines 3. move cursor to B 4. P - pull text in after cursor p - pull text in before cursor YANK OPERATOR TO BUFFER yw - yank word y$ - yank from cursor to EOL yG - yank from cursor to EOF yy - yank complete current line p - paste from buffer after cursor P - paste from buffer before cursor USEFUL COMMANDS . - repeat last command u - undo last command U - undo changes made to current line J - join the next line to the current line ^G - Show the current filename and status ! - Ejecuta uan linea del shell :1,$s/old/new/g - global search and replace old with new * :.,$d - delete from current line to eof :r filename - read filename into this vi buffer :n,mw filename - write lines n through m to filename * special characters prefix with \ (backslash) Examples: --------- The following example performs a global search with replace. We want to search for "feo" and change it for "lindo": :g/feo/s//lindo/g If you want to use special characters you need to use \ (backslash). For example: to replace all the $ with **: :g/\$/s//**/g :1,5de Delete from line 1 to 5. :1,5co20 Copy from line 20 5 lines :1,5mo20 Same as before but cutting those lines :g/XXX/s//YYY/g Changes on the full text XXX with YYY. :s/old/new replace next occurence of old with new :s/old/new/g replace all occurences on the line :x,ys/old/new/g replace all ocurrences from line x to y :%s/old/new/g replace all occurrences in file :%s/old/new/gc same as above, with confirmation