VI Reference Card

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Yanking text

Vi Reference Card by www.Faysal Khan.Org


Like deletion, almost all yank commands are performed
Regular expressions
any single character except newline (dot)
by typing y followed by a motion. For example y$ yanks zero or more repeats *
Modes to the end of line. Two other yank commands are:
Vi has two modes: insertion mode, and command mode. any character in set [...]
The editor begins in command mode, where cursor line y y any character not in set [^ ...]
movement and text deletion and pasting occur. line : y beginning, end of line ^,$
Insertion mode begins upon entering an insertion or beginning, end of word \< , \>
change command. [ESC] returns the editor to command Changing text grouping \(. . . \)
mode (where you can quit, for example by typing :q!). The change command is a deletion command that contents of n th grouping \n
Most commands execute as soon as you type them leaves the editor in insert mode. It is performed by
except for “colon” commands which execute when you typing c followed by a motion. For example cw changes Counts
press the return key. a word. A few other change commands are: Nearly every command may be preceded by a number
that specifies how many times it is to be performed. For
Quitting to end of line C example 5dw will delete 5 words and 3fe will move the
exit, saving changes :x line c c cursor forward to the 3rd occurance of the letter e. Even
quit (unless changes) :q insertions may be repeated conveniently with this
quit (force, even if unsaved) :q! Putting text method, say to insert the same line 100 times.
put after position or after line P
Inserting text put before position or before line P Ranges
insert before cursor, before line i , I Ranges may precede most “colon” commands and
Registers cause them to be executed on a line or lines. For
append after cursor, after line a , A Named registers may be specified before any deletion, example :3,7d would delete lines 3−7. Ranges are
open new line after, line before o , O change, yank, or put command. The general prefix has commonly combined with the :s command to perform a
replace one char, many char r , R the form "c where c may be any lower case letter. For replacement on several lines, as with :.,
example, "adw deletes a word into register a. It may $s/pattern/string/g to make a replacement from the
Motion thereafter be put back into the text with an appropriate current line to the end of the file.
left, down, up, right h,j,k,l put command, for example "ap.
next word, blank delimited word w,W lines n-m :n ,m
beginning of word, of blank delimited word b,B current line :.
Markers last line :$
end of word, of blank delimited word e,E Named markers may be set on any line of a file. Any marker c
sentence back, forward (,) :’c
lower case letter may be a marker name. Markers may all lines :%
paragraph back, forward {,} also be used as the limits for ranges.
beginning, end of line 0,$ all matching lines :g/pattern /
beginning, end of file 1G , G set marker c on this line mc
line n n G or :n goto marker c 'c Files
forward, back to char c fc , Fc goto marker c first non-blank 'c write file (current file if no name given) :w file
forward, back to before char c tc , Tc append file (current file if no name given) :w >>file
top, middle, bottom of screen H,M,L Search for strings read file after line :r file
search forward /string read program output :r !program
Deleting text search backward ?string next file :n
Almost all deletion commands are performed by typing repeat search in same, reverse direction n,N previous file :p
d followed by a motion. For example dw deletes a word. edit new file :e file
Replace replace line with program output :.!program
A few other deletions are:
The search and replace function is accomplished
character to right, left x,X with the :s command. It is commonly used in Other
to end of line D combination with ranges or the :g command (below). toggle upper/lower case ~
line dd join lines J
line :d replace pattern with string :s/pattern /string /flags repeat last text-changing command .
flags: all on each line, confirm each g,c undo last change, all changes on line u,U
repeat last :s command & .
© 2011 Faisal Khan - www.FaysalKhan.org - licensed under the terms of the GNU Free Documentation License Version 1.3 or later

You might also like