Vi Quick Ref

download Vi Quick Ref

of 1

Transcript of Vi Quick Ref

  • 8/13/2019 Vi Quick Ref

    1/1

    1995, 1997, 1998 Phillip Farrell VI Quick Reference -- Basic Commands 10/7/98

    Notations and ConventionsCommands you type are in fixedfont.Italics= substitute desired value. means press RETURN key.

    ^X means press CONTROL and X keystogether. Boxed commands switch to insertmode; press ESC key to end new text.

    Beginning Your Edit Sessionvi file edit or create filevi -r show rescued filesvi -r file recover rescued file

    Ending Your Edit Session:q! quit and discard changes:wq or ZZ quit and save changes:wq new save as new and quit

    Controlling Your Screen Display^R Eliminate @ lines^L Repaint screen after interruption:set wm=x Auto word wrap atx

    chars before line end:set nu Show line numbers on

    screen (not added to file):set nonu Stop showing line

    numbers on screen(put set commands into .exrc file forautomatic settings each time you start vi)

    Moving the Cursorh one position leftk one line upj one line downl (letter "ell") one position right0 (zero) beginning of current line$ end of current linew forward one wordW ... including punctuationb backward one wordB ... including punctuatione forward to end of current word

    E ... including punctuation

    - up one line, 1st non-blank char+ or down line, 1st non-blank charH beginning of first screen lineM beginning of middle screen line

    L beginning of last screen line

    Paging Through Text^F forward one screen^B backward one screen^D scroll down half screen^U scroll up half screennG move screen to line number nG move screen to last line

    Searching Through Text/pattern forward search for pattern

    (regular expression syntax)?pattern backward search for pattern

    (regular expression syntax)n repeat search for next occurrenceN repeat search, reverse direction

    Creating TextPress ESC key to end new text. To enter acontrol character as text, precede it with ^Va append text after cursorA append text at end of current linei insert text before cursorI insert text before first non-blank

    character on current lineo open new line after current lineO open new line before current line:r

    file insert contents offileafter current line

    Modifying Text -- Simple Changes(* = can be preceded with a repeat count,e.g., 5xor 16dd. Count starts at cursor.)x delete character at cursor *dd delete line with cursor *dw delete current word *D delete to end of line.

    rc change character at cursor to c

    cw replace current word with new text *cc replace entire current line *C replace line from cursor to endJ join current line with next

    ~ change case of cur rent characteru undo last text change. repeat last text-change command

    (could be at new location)

    Modifying Text -- Operators(Can precede with repeat count. Double toaffect whole lines , e.g., 5yy . Follow withone of the cursor movement or searchingcommands to select affected text, e.g., dworc5w or y/Geology).d delete

    c change (replace with new text)y yank (copy) to buffer! filter selected text through command

    typed on status line, then replacewith command output

    > shift line(s) right one tab position

    Moving Text Around(Use these commands to insert a copy of textfrom buffer. Deleted, replaced (old), oryanked text goes to unnamed buffer bydefault. Or use named buffer a thru z by

    prefixing command with " operator andbuffer name, e.g., "a5yyand then "ap)p copy buffer text after cursor or line"ap ... using named buffer a (or b,c, etc)P copy buffer text before cursor or line"aP ... using named buffer a (or b,c, etc)xp transpose characters

    Global Text Substitution:n,m s/old/new/g

    Change all occurrences of regularexpression oldto text newon all lines nthru m. Can use symbolic line numbers"." (current line) or "$" (last line).