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

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

VIM is a text editor with two modes: command mode for navigation and editing and insert mode for text entry. Command mode allows cursor movement, deletion, and other edits using keys like h, j, k, l or commands like G and dd. Insert mode is entered using a, i, o, or O and lets the user insert text, exiting back to command mode with Esc. Useful commands include w to move forward a word, dd to delete a line, and :wq to write changes and quit.

Uploaded by

snadmin
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)
36 views

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

VIM is a text editor with two modes: command mode for navigation and editing and insert mode for text entry. Command mode allows cursor movement, deletion, and other edits using keys like h, j, k, l or commands like G and dd. Insert mode is entered using a, i, o, or O and lets the user insert text, exiting back to command mode with Esc. Useful commands include w to move forward a word, dd to delete a line, and :wq to write changes and quit.

Uploaded by

snadmin
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

12/04/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
^DDownhalfscreenful
$Movecursortotheendofcurrentline
http://www.radford.edu/~mhtay/CPSC120/VIM_Editor_Commands.htm

1/4

12/04/2015

VIMEditorCommands

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
JJoinnextlinedowntotheendofthecurrentline
FileManipulationCommands
:wWriteworkspacetooriginalfile
:wfileWriteworkspacetonamedfile
http://www.radford.edu/~mhtay/CPSC120/VIM_Editor_Commands.htm

2/4

12/04/2015

VIMEditorCommands

: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
OpeningaNewFile
Step1typevimfilename(createafilenamedfilename)
Step2typei(switchtoinsertmode)
Step3entertext(enteryourAdaprogram)
Step4hitEsckey(switchbacktocommandmode)
http://www.radford.edu/~mhtay/CPSC120/VIM_Editor_Commands.htm

3/4

12/04/2015

VIMEditorCommands

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