0% found this document useful (0 votes)
101 views4 pages

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 Esc key exits insert mode. Useful commands include w to move forward a word, dd to delete a line, p to paste, and :wq to write and quit.

Uploaded by

Gyurme Yeshe
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)
101 views4 pages

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 Esc key exits insert mode. Useful commands include w to move forward a word, dd to delete a line, p to paste, and :wq to write and quit.

Uploaded by

Gyurme Yeshe
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

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