0% found this document useful (0 votes)
41 views

VIM Editor Commands: (Ex. 10G Goes To Line 10)

Vim is a text editor that has two modes: command mode for navigation and editing and insert mode for text entry. Command mode allows moving the cursor, deleting text, and more using keys like h, j, k, l or commands like G. Insert mode is entered using a, i, o or O and lets the user insert text. The document then lists many useful Vim commands for text entry, movement, deletion, file manipulation and more.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

VIM Editor Commands: (Ex. 10G Goes To Line 10)

Vim is a text editor that has two modes: command mode for navigation and editing and insert mode for text entry. Command mode allows moving the cursor, deleting text, and more using keys like h, j, k, l or commands like G. Insert mode is entered using a, i, o or O and lets the user insert text. The document then lists many useful Vim commands for text entry, movement, deletion, file manipulation and more.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

6/4/2016 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
6/4/2016 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
6/4/2016 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
6/4/2016 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