<<

Quick Reference

Entering/leaving ex Specifying terminal %exname edit name,start end %setenvTERM type csh and all version 6 %ex+nname ... at line n $TERM=type;export TERM sh in Version 7 %ex−ttag start at tag See also tset(1) %ex−r list savedfiles Some terminal types %ex−rname recoverfile name %exname ... edit first; rest via :n 2621 43 adm31 dw1 h19 %ex−Rname read only 2645 733 adm3a dw2 i100 :x , saving changes 300s 745 c100 gt40 mime :q! exit, discarding changes 33 act4 dm1520 gt42 owl Ex states 37 act5 dm2500 h1500 t1061 4014 adm3 dm3025 h1510 vt52 Command Normal and initial state. Input Initializing options prompted for by :.Your character cancels partial command. EXINIT place set’s here in environment var. Insert Entered by aiand .Arbitrary text set x enable option then terminates with line having only . set nox disable option character on it or abnormally with set x=val give value val interrupt. set showchanged options Open/visual Entered by open or ,terminates with set all showall options Q or ˆ\. set x? showvalue of option x Ex commands Useful options abbrev ab next n unabbrev una autoindent ai supply indent append a number nu undo u autowrite aw before changing files args open o unmap unm ignorecase ic in scanning change c preserve pre version ve lisp ( ){}are s-exp’s copy co print p visual vi list print ˆI for tab, $ at end delete d put pu write magic . [*special in patterns edit e quit q xit x number nu number lines file f read re yank ya paragraphs para names start ... global g recover rec window z redraw simulate smart terminal insert i rewind rew escape ! scroll command mode lines j set se lshift < sections sect macro names ... list l shell sh print next CR shiftwidth sw for <>,and input ˆD map source so resubst & showmatch sm to ) and } as typed mark ma stop st rshift > showmode smd showinput mode description move m substitute s scroll ˆD slowopen slowchokeupdates during insert Ex command addresses window visual mode lines wrapscan ws around end of buffer? n line n /pat next with pat wrapmargin wm automatic line splitting . current ?pat previous with pat $ last x-nnbefore x Scanning patternformation + next x,yxthrough y ↑ beginning of line − previous ´x marked with x $ end of line +nnforward ´´ previous context . anycharacter % 1,$ \< beginning of word \> end of word [str] anychar in str [↑str] ... not in str [x−y] ... between x and y * anynumber of preceding Vi Quick Reference

Entering/leaving vi manipulation %viname edit name at :w write back changes %vi+nname ... at line n :wq write and quit %vi+name ... at end :q quit %vi−r list savedfiles :q! quit, discard changes %vi−rname recoverfile name :e name edit file name %viname ... edit first; rest via :n :e! reedit, discard changes %vi−ttag start at tag :e + name edit, starting at end %vi+/pat name search for pat :e +n edit starting at line n %view name read only mode :e # edit alternate file ZZ exit from vi, saving changes ˆ↑ synonym for :e # ˆZ stop vi for later resumption :w name write file name name overwrite file name The display :w! :sh run shell, then return Last line Error messages, echoing input to :/?and !, :!cmd run cmd,then return feedback about i/o and large changes. :n edit next file in arglist @lines On screen only,not in file. :n args specify newarglist ˜lines Lines past end of file. :f showcurrent file and line ˆx Control characters, ˆ? is delete. ˆG synonym for :f tabs to spaces, cursor at last. :ta tag to tag file entry tag ˆ] :ta,following word is tag Vi states Positioning within file Command Normal and initial state. Others return here. ESC (escape) cancels partial com- ˆF forward screenfull mand. ˆB backward screenfull Insert Entered by aiAIoOcCsS R.Arbitrary ˆD scroll down half screen text then terminates with ESC character,or ˆU scroll up half screen abnormally with interrupt. G goto line (end default) Last line Reading input for :/?or !;terminate with /pat next line matching pat ESC or CR to execute, interrupt to cancel. ?pat prevline matching pat n repeat last / or ? Counts beforevicommands N reverse last / or ? line/column number zG| /pat/+n n’th line after pat scroll amount ˆD ˆU ?pat?−n n’th line before pat replicate insert aiAI ]] next section/function repeat effect rest [[ previous section/function % find matching (){or } Simple commands Adjusting the screen dw delete a word de ... leaving punctuation ˆL and redraw delete a line ˆR retype, eliminate @ lines 3dd ... 3 lines zCR redraw, current at windowtop itextESC insert text abc z− ... at bottom cwnewESC change word to new z. ... at center easESC pluralize word /pat/z− pat line at bottom xp transpose characters zn . use n line window ˆE scroll windowdown1line Interrupting, cancelling ˆY scroll windowup1line ESC end insert or incomplete cmd ˆ? (delete or rubout) interrupts ˆL reprint screen if ˆ? scrambles it Marking and returning Corrections during insert `` previous context ˆH erase last character ´´ ... at first non-white in line ˆW erases last word mx mark position with letter x erase your erase, same as ˆH `x to mark x kill your kill, erase input this line ´x ... at first non-white in line \ escapes ˆH,your erase and kill ESC ends insertion, back to command Line positioning ˆ? interrupt, terminates insert H home windowline ˆD backtab over autoindent L last windowline ↑ˆD kill autoindent,sav e for next M middle windowline 0ˆD ... but at margin next also + next line, at first non-white ˆV quote non-printing character − previous line, at first non-white CR return, same as + Insert and replace ↓ or j next line, same column a append after cursor ↑ or k previous line, same column i insert before append at end of line Character positioning A I insert before first non-blank ↑ first non white o open line below 0 beginning of line O open above $ end of line rx replace single char with x h or → forward R replace characters or ← backwards l Operators (double to affect lines) ˆH same as ← space same as → d delete fx find x forward c change Fx f backward < left shift tx upto x forward > right shift Tx back upto x ! filter through command ; repeat last fFtor T = indent for LISP , inverse of ; y yank lines to buffer to specified column | Miscellaneous operations % find matching ({)or } change rest of line Words, sentences, paragraphs C D delete rest of line w word forward s substitute chars b back word S substitute lines e end of word J join lines ) to next sentence x delete characters } to next paragraph X ... before cursor ( back sentence Y yank lines back paragraph { Yank and put W blank delimited word B back W p put back lines E to end of W P put before "xp put from buffer x Commands for LISP "xy yank to buffer x ) Forward s-expression "xd delete into buffer x ... but don’tstop at atoms } Undo, redo, retrieve ( Back s-expression { ... but don’tstop at atoms u undo last change U restore current line . repeat last change "d p retrieve d’thlast delete