Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Vi Editor Cheat Sheet: Movement, Searches, Editing, and Other Commands, Cheat Sheet of Operating Systems

This cheat sheet provides a comprehensive list of vi editor commands for movement, searches, editing, and other functions. It covers both basic and advanced commands, such as scrolling, marking positions, inserting text, changing text, and invoking the editor. Use this cheat sheet to quickly navigate and edit files in vi.

Typology: Cheat Sheet

2019/2020

Uploaded on 10/23/2020

ekachakra
ekachakra 🇺🇸

4.6

(33)

269 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Vi Editor Cheat Sheet
Movement Commands
Character
h, j, k, lLeft, down, up, right
Text
w, W, b, BForward, backward by word
e, E End of word
(, )Beginning of next, previous sentence
{, }Beginning of next, previous paragraph
[[, ]] Beginning of next, previous section
Lines
0, $First, last position of current line
^First non-blank character of current line
+, -First character of next, previous line
HTop line of screen
MMiddle line of screen
LLast line of screen
nH, nLLine n from top, bottom of screen
Scrolling
[Ctrl]F, [Ctrl]B Scroll forward, backward one screen
[Ctrl]D, [Ctrl]U Scroll down, up one-half screen
[Ctrl]E, [Ctrl]Y Show one more line at bottom, top of window
z[Enter] Scroll until line with cursor is at top of screen
z. Scroll until line with cursor is at middle of screen
z- Scroll until line with cursor is at bottom of screen
Searches
/pattern Search forward for pattern
?pattern Search backward for pattern
n, NRepeat last search in same, opposite direction
/, ?Repeat previous search forward, backward
fxsearch forward for character x in current line
Fxsearch backward for character x in current line
txsearch forward for character before x in current line
Txsearch backward for character after x in current line
;Repeat previous current-line search
,Repeat previous current-line search in opposite direction
Line Number
[Ctrl]GDisplay current line number
nGMove to line number n
GMove to last line in file
:nmove to line number n
Marking Position
mxMark current position as x
`xMove cursor to x
`` Return to previous mark or context
'xMove to beginning of line containing mark x
'' Return to beggining of line containing previous mark
Editing Commands
Insert
i, aInsert text before, after cursor
I, AInsert text at beginning, end of line
o, OOpen new line for text below, above cursor
Change
rReplace with next typed characer
pf2

Partial preview of the text

Download Vi Editor Cheat Sheet: Movement, Searches, Editing, and Other Commands and more Cheat Sheet Operating Systems in PDF only on Docsity!

Vi Editor Cheat Sheet

Movement Commands

Character

h, j, k, l Left, down, up, right

Text

w, W, b, B Forward, backward by word e, E End of word (, ) Beginning of next, previous sentence {, } Beginning of next, previous paragraph [[, ]] Beginning of next, previous section

Lines

0 , $ First, last position of current line ^ First non blank character of current line +, - First character of next, previous line H Top line of screen M Middle line of screen L Last line of screen n H, n L Line n from top, bottom of screen

Scrolling

[Ctrl]F, [Ctrl]B Scroll forward, backward one screen [Ctrl]D, [Ctrl]U Scroll down, up one half screen [Ctrl]E, [Ctrl]Y Show one more line at bottom, top of window z[Enter] Scroll until line with cursor is at top of screen z. Scroll until line with cursor is at middle of screen z- Scroll until line with cursor is at bottom of screen

Searches

/ pattern Search forward for pattern ? pattern Search backward for pattern n, N Repeat last search in same, opposite direction /,? Repeat previous search forward, backward f x search forward for character^ x^ in current line F x search backward for character^ x^ in current line t x search forward for character before x in current line T x search backward for character after x in current line ; Repeat previous current line search , Repeat previous current line search in opposite direction

Line Number

[Ctrl]G Display current line number n G Move to line number^ n G Move to last line in file : n move to line number n

Marking Position

m x Mark current position as^ x ` x Move cursor to^ x `` Return to previous mark or context ' x Move to beginning of line containing mark^ x '' Return to beggining of line containing previous mark

Editing Commands

Insert

i, a Insert text before, after cursor I, A Insert text at beginning, end of line o, O Open new line for text below, above cursor

Change

r Replace with next typed characer

~ Change between uppercase and lowercase c m Change text block defined by movement command^ m^ (e.g., cw changes next word) cc Change current line C Change to end of line R Type over characters s Delete character and continue typing S Delete current line and continue typing

Delete, Move

x Delete character X Delete character to the left of the cursor d m Delete text block defined by movement command m (e.g., dw deletes next word) dd Delete current line D Delete to end of line p, P Put deleted text before, after cursor " n p Put text from delete buffer number^ n^ after cursor (for last nine deletions)

Yank (copy)

y m Yank (copy) text block defined by movement command m (e.g., yw yanks next word) yy, Y Yank current line " a yy Yank current line into named buffer^ a p, P Put yanked text before, after cursor " a P Put text from buffer^ a^ before cursor

Other Commands

. Repeat last edit command u Undo last edit U Undo changes to current line J Join two lines [Ctrl]L, [Ctrl]R Redraw screen Invoking vi vi file Invoke vi editor on file vi file1 file2 Invoke vi editor on files sequentially view file Invoke vi editor on^ file^ in read only mode vi -R file Invoke vi editor on^ file^ in read only mode vi -r file Recover^ file^ and recent edits after system crash vi + file Open^ file^ at last line vi + n file Open^ file^ at line number^ n vi +/ pattern file Open file at pattern Exit and Save Commands ZZ Save file and quit :x Save file and quit :wq Save ("write") file and quit :w Save file :w! Save file (overriding protection) :30,60w newfile Save lines 30 through 60 as file^ newfile :30,60w>> file Append lines 30 through 60 to file file :w %. new Save current buffer named^ file^ as^ file.new :q Quit :q! Quit, discarding any changes Q Quit vi and invoke ex :e file2 Edit^ file2^ without leaving vi :e! file2 Discard changes to current file, then edit^ file2^ without leaving vi :n Edit next file :e! Discard all changes since last save :e# Edit alternate file