You are on page 1of 4

8/24/2015 VIMEditorCommands

VIMEditorCommands

Vimisaneditortocreateoreditatextfile.

Therearetwomodesinvim.Oneisthecommandmodeandanotheristheinsertmode.

Inthecommandmode,usercanmovearoundthefile,deletetext,etc.

Intheinsertmode,usercaninserttext.

Changingmodefromonetoanother

Fromcommandmodetoinsertmodetypea/A/i/I/o/O(seedetailsbelow)

FrominsertmodetocommandmodetypeEsc(escapekey)

SomeusefulcommandsforVIM

TextEntryCommands(Usedtostarttextentry)

aAppendtextfollowingcurrentcursorposition

AAppendtexttotheendofcurrentline

iInserttextbeforethecurrentcursorposition

IInserttextatthebeginningofthecursorline

oOpenupanewlinefollowingthecurrentlineandaddtextthere

OOpenupanewlineinfrontofthecurrentlineandaddtextthere

Thefollowingcommandsareusedonlyinthecommandsmode.
CursorMovementCommands

hMovesthecursoronecharactertotheleft

lMovesthecursoronecharactertotheright

kMovesthecursoruponeline

jMovesthecursordownoneline

nGor:nCursorgoestothespecified(n)line

(ex.10Ggoestoline10)

^F(CTRlF)Forwardscreenful

^BBackwardscreenful

^fOnepageforward

^bOnepagebackward

^UUphalfscreenful

http://www.radford.edu/~mhtay/CPSC120/VIM_Editor_Commands.htm 1/4
8/24/2015 VIMEditorCommands

^DDownhalfscreenful

$Movecursortotheendofcurrentline

0(zero)Movecursortothebeginningofcurrentline

wForwardoneword

bBackwardoneword

ExitCommands

:wqWritefiletodiskandquittheeditor

:q!Quit(nowarning)

:qQuit(awarningisprintedifamodifiedfilehasnotbeensaved)

ZZSaveworkspaceandquittheeditor(sameas:wq)

:10,25wtemp

writelines10through25intofilenamedtemp.Ofcourse,otherline

numberscanbeused.(Use:ftofindoutthelinenumbersyouwant.

TextDeletionCommands

xDeletecharacter

dwDeletewordfromcursoron

dbDeletewordbackward

ddDeleteline

d$Deletetoendofline

d^(dcaret,notCTRLd)Deletetobeginningofline

Yank(hasmostoftheoptionsofdelete)VI'scopycommmand

yyyankcurrentline

y$yanktoendofcurrentlinefromcursor

ywyankfromcursortoendofcurrentword

5yyyank,forexample,5lines

Paste(usedafterdeleteoryanktorecoverlines.)

ppastebelowcursor

Ppasteabovecursor

"2ppastefrombuffer2(thereare9)

uUndolastchange

URestoreline
http://www.radford.edu/~mhtay/CPSC120/VIM_Editor_Commands.htm 2/4
8/24/2015 VIMEditorCommands

JJoinnextlinedowntotheendofthecurrentline

FileManipulationCommands

:wWriteworkspacetooriginalfile

:wfileWriteworkspacetonamedfile

:efileStarteditinganewfile

:rfileReadcontentsofafiletotheworkspace

Tocreateapagebreak,whileintheinsertmode,presstheCTRLkey

Andl.^Lwillappearinyourtextandwillcausetheprintertostart

Anewpage.

OtherUsefulCommands

Mostcommandscanberepeatedntimesbytypinganumber,n,before

thecommand.Forexample10ddmeansdelete10lines.

.Repeatlastcommand

cwChangecurrentwordtoanewword

rReplaceonecharacteratthecursorposition

RBeginoverstrikeorreplacemodeuseESCkeytoexit

:/patternSearchforwardforthepattern

:?patternSearchbackwardforthepattern

n(usedaftereitherofthe2searchcommandsaboveto

continuetofindnextoccurrenceofthepattern.

:g/pat1/s//pat2/greplaceeveryoccurrenceofpattern1(pat1)with

pat2

Example:g/tIO/s//Ada.Text_IO/g

ThiswillfindandreplacetIObyAda.text_IOeverywhereinthefile.

:g/a/s///greplacethelettera,byblank

:g/a/s///greplaceabynothing

note:Eventhiscommandbeundonebyu

Examples

http://www.radford.edu/~mhtay/CPSC120/VIM_Editor_Commands.htm 3/4
8/24/2015 VIMEditorCommands

OpeningaNewFile

Step1typevimfilename(createafilenamedfilename)

Step2typei(switchtoinsertmode)

Step3entertext(enteryourAdaprogram)

Step4hitEsckey(switchbacktocommandmode)

Step5type:wq(writefileandexitvim)

EditingtheExistingFile

Step1typevimfilename(edittheexistingfilenamedfilename)

Step2movearoundthefileusingh/j/k/lkeyoranyappropriatecommand
hMovesthecursoronecharactertotheleft

lMovesthecursoronecharactertotheright

kMovesthecursoruponeline

jMovesthecursordownoneline

nGor:nCursorgoestothespecified(n)line

(ex.10Ggoestoline10)

Step3editrequiredtext(replaceordeleteorinsert)

Step4hitEsckey(exitfrominsertmodeifyouinsertorreplacetext)

Step5type:wq

http://www.radford.edu/~mhtay/CPSC120/VIM_Editor_Commands.htm 4/4

You might also like