0% found this document useful (0 votes)
19 views2 pages

Vi Cheat Sheet

Uploaded by

rajdharmkar
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)
19 views2 pages

Vi Cheat Sheet

Uploaded by

rajdharmkar
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/ 2

Vi Cheat Sheet

Launching Vi Editor Joining Lines


vi Opens the editor in default mode J Joins two lines
vi
Opens the specified file or creates a new file
<filename.txt yyp Repeats the current line
in vi editor
>
Switch to Insert Mode ddp Swaps two lines
i Changes to insert mode Navigating within a File
I Inserts text at the start of the current line k Moves up one line
a Appends after the cursor’s current position j Moves down one line
A Appends to the end of the line h Moves one character to the left
o Adds a new line beneath the current one l Moves right one character

O Opens a new line above the current line G Navigates to the last line of a file

Jump Line Commands XG Navigates to line X in a file


G Indicates you to the file's final line gg Navigates to the first line of a file
I Takes you to your last position in the file Saving & Closing File
Copy & Paste Commands wq or ZZ Saves your work and exit vi

yy Copies (yanks) a line of text w Continues editing after saving


Copies the current word from the character
yw with the lowercase w cursor is on, until the w! Saves (and write to a non-writable file)
word is finished
Paste a line of yanked text after the current
p q! Quits vi without saving the changes
line
P Paste before the current line Text Buffers
Searching String "add Deletes the current line and insert text into buffer a

/string Forwards lookup for a given string "ap Paste the line from buffer a

?string Backwards lookup for a given string Set Commands


/^string Forwards search string at the start of a line set ic Set case insensitivity while searching

/string$ Forwards search string at line's end set ai Sets auto indention
Proceeds to the next occurrence of the
n set noai Unsets auto indention
searched string
Looks for the word he (rather than there, Shows lines with line numbers on the left side of
/\<he\> set nu
here, and so on) the screen
/pl[abc]ce Looks up the terms place, plbce, and plcce set sw Sets the width of a software tabstop

If wrapscan is enabled and the word is not found at


set ws
the end of the file, it will look for it at the beginning
Prepared By: Lamisa Musharrat Copyright ©2023 linuxsimply.com| All rights reserved.
Vi Cheat Sheet
If this option is set to a value greater than zero, the
Changing Text Commands set wm
editor will "word wrap" automatically

Removes the line's contents, returning you


cc set ro Sets the file type to "read only"
to insert mode
Changes the current word with new text,
cw set term Prints the terminal type
starting with the character under cursor
Overwrites characters beginning with the
R set bf Discards control characters from input
cursor
Substitutes one character under cursor
s
continue to insert Scrolling Commands
Substitutes entire line and begin to insert at
S CTRL+D Moves the screen down by half a page
the beginning of the line

Other Vi Shortcuts CTRL+F Scrolls the screen down by a full page

b Returns to the word's beginning CTRL+U Scrolls the screen up by half a page

e Goes to the end of the word CTRL+B Scrolls the screen up by a full page

Xyy Yanks X number of lines CTRL+E Scrolls the screen up by one line

num Shows the line number of the current line CTRL+Y Scrolls the screen down by one line

Switches to Command mode /Terminate


Esc CTRL+I Redraws the screen
insert mode

xp Switches two characters

cw Changes word

~ Changes the case of an individual character

Undo & Repeat Commands


u Undo the most recent change

U Reverts all changes made to the entire line

. Repeats the last command

Prepared By: Lamisa Musharrat Copyright ©2023 linuxsimply.com| All rights reserved.

You might also like