Vous êtes sur la page 1sur 5

1/24/2016 ViCheatSheet

ViCheatSheet

Modes
Markers
Quitting
Searching
InsertingText
ReplacingText
Motion
RegularExpressions
DeletingText
Counts
Yanking
Ranges
ChangingText
Files
PuttingText
Other
Buffers

ClickherefortheAdvancedVICheatsheet

Modes

Vihastwomodesinsertionmodeandcommandmode.Theeditorbeginsincommandmode,wherethecursor
movementandtextdeletionandpastingoccur.Insertionmodebeginsuponenteringaninsertionorchangecommand.
[ESC]returnstheeditortocommandmode(whereyoucanquit,forexamplebytyping:q!).Mostcommandsexecute
assoonasyoutypethemexceptfor"colon"commandswhichexecutewhenyoupresstheruturnkey.

Quitting

:x Exit,savingchanges
:q Exitaslongastherehavebeennochanges
ZZ Exitandsavechangesifanyhavebeenmade
:q! Exitandignoreanychanges

InsertingText

i Insertbeforecursor
I Insertbeforeline
a Appendaftercursor
A Appendafterline
o Openanewlineaftercurrentline
O Openanewlinebeforecurrentline
r Replaceonecharacter
R Replacemanycharacters

Motion

h Moveleft
j Movedown
k Moveup
l Moveright
w Movetonextword
W Movetonextblankdelimitedword

http://www.lagmonster.org/docs/vi.html#quit 1/5
1/24/2016 ViCheatSheet

b Movetothebeginningoftheword
B Movetothebeginningofblankdelimtedword
e Movetotheendoftheword
E MovetotheendofBlankdelimitedword
( Moveasentenceback
) Moveasentenceforward
{ Moveaparagraphback
} Moveaparagraphforward
0 Movetothebeginingoftheline
$ Movetotheendoftheline
1G Movetothefirstlineofthefile
G Movetothelastlineofthefile
nG Movetonthlineofthefile
:n Movetonthlineofthefile
fc Moveforwardtoc
Fc Movebacktoc
H Movetotopofscreen
M Movetomiddleofscreen
L Movetobottonofscreen
% Movetoassociated(),{},[]

DeletingText

Almostalldeletioncommandsareperformedbytypingdfollowedbyamotion.Forexample,dwdeletesaword.Afew
otherdeletesare:
x Deletecharactertotherightofcursor
X Deletecharactertotheleftofcursor
D Deletetotheendoftheline
dd Deletecurrentline
:d Deletecurrentline

YankingText

Likedeletion,almostallyankcommandsareperformedbytypingyfollowedbyamotion.Forexample,y$yankstothe
endoftheline.Twootheryankcommandsare:
yy Yankthecurrentline
:y Yankthecurrentline

Changingtext

Thechangecommandisadeletioncommandthatleavestheeditorininsertmode.Itisperformedbytypingcfollowed
byamotion.Forwxamplecwchangesaword.Afewotherchangecommandsare:
C Changetotheendoftheline
cc Changethewholeline

http://www.lagmonster.org/docs/vi.html#quit 2/5
1/24/2016 ViCheatSheet

Puttingtext

p Putafterthepositionoraftertheline
P Putbeforethepoitionorbeforetheline

Buffers

Namedbuffersmaybespecifiedbeforeanydeletion,change,yankorputcommand.Thegeneralprefixhastheform"c
wherecisanylowercasecharacter.forexample,"adwdeletesawordintobuffera.Itmaythereafterbeputbackinto
textwithanappropriate"ap.

Markers

Namedmarkersmaybesetonanylineinafile.Anylowercaselettermaybeamarkername.Markersmayalsobe
usedaslimitsforranges.
mc Setmarkerconthisline
`c Gotobeginningofmarkercline.
'c Gotofirstnonblankcharacterofmarkercline.

Searchforstrings

/string Searchforwardforstring
?string Searchbackforstring
n Searchfornextinstanceofstring
N Searchforpreviousinstanceofstring

Replace

Thesearchandreplacefunctionisaccomplishedwiththe:scommand.Itiscommonlyusedincombinationwith
rangesorthe:gcommand(below).
:s/pattern/string/flags Replacepatternwithstringaccordingtoflags.
g FlagReplacealloccurencesofpattern
c FlagConfirmreplaces.
& Repeatlast:scommand

RegularExpressions

.(dot) Anysinglecharacterexceptnewline
* zeroormoreoccurancesofanycharacter
[...] Anysinglecharacterspecifiedintheset
[^...] Anysinglecharacternotspecifiedintheset
^ Anchorbeginningoftheline
$ Anchorendofline
\< Anchorbeginingofword
http://www.lagmonster.org/docs/vi.html#quit 3/5
1/24/2016 ViCheatSheet

\> Anchorendofword
\(...\) Groupingusuallyusedtogroupconditions
\n Contentsofnthgrouping

[...]SetExamples
[AZ] TheSETfromCapitalAtoCapitalZ
[az] TheSETfromlowercaseatolowercasez
[09] TheSETfrom0to9(Allnumerals)
[./=+] TheSETcontaining.(dot),/(slash),=,and+
[AF] TheSETfromCapitalAtoCapitalFandthedash(dashesmustbespecifiedfirst)
[09AZ] TheSETcontainingallcapitallettersanddigitsandaspace
Inthefirstposition,theSETfromCapitalAtoCapitalZ
[AZ][azAZ]
Inthesecondcharacterposition,theSETcontainingallletters

RegularExpressionExamples
/Hello/ MatchesifthelinecontainsthevalueHello
/^TEST$/ MatchesifthelinecontainsTESTbyitself
/^[azAZ]/ Matchesifthelinestartswithanyletter
/^[az].*/ Matchesifthefirstcharacterofthelineisazandthereisatleastonemoreofanycharacterfollowingit
/2134$/ Matchesiflineendswith2134
Matchesisthelinecontains21or35
/\(21|35\)/
Notetheuseof()withthepipesymboltospecifythe'or'condition
/[09]*/ Matchesiftherearezeroormorenumbersintheline
/^[^#]/ Matchesifthefirstcharacterisnota#intheline
Notes:
1.Regularexpressionsarecasesensitive
2.Regularexpressionsaretobeusedwherepatternisspecified

Counts

Nearlyeverycommandmaybeprecededbyanumberthatspecifieshowmanytimesitistobeperformed.For
example,5dwwilldelete5wordsand3fewillmovethecursorforwardtothe3rdoccurenceofthelettere.Even
insertionsmayberepeatedconvenientlywiththismethod,saytoinsertthesameline100times.

Ranges

Rangesmayprecedemost"colon"commandsandcausethemtobeexecutedonalineorlines.Forexample:3,7d
woulddeletelines37.Rangesarecommonlycombinedwiththe:scommandtoperformareplacementonseveral
lines,aswith:.,$s/pattern/string/gtomakeareplacementfromthecurrentlinetotheendofthefile.
:n,m RangeLinesnm
:. RangeCurrentline
:$ RangeLastline
:'c RangeMarkerc
:% RangeAlllinesinfile
:g/pattern/ RangeAlllinesthatcontainpattern

Files

:wfile Writetofile

http://www.lagmonster.org/docs/vi.html#quit 4/5
1/24/2016 ViCheatSheet

:rfile Readfileinafterline
:n Gotonextfile
:p Gotopreviosfile
:efile Editfile
!!program Replacelinewithoutputfromprogram

Other

~ Toggleuppandlowercase
J Joinlines
. Repeatlasttextchangingcommand
u Undolastchange
U Undoallchangestoline

Returntothetop

PageproducedbyLagmonsterOct2000

http://www.lagmonster.org/docs/vi.html#quit 5/5

Vous aimerez peut-être aussi