Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
Enroll Now
Hereโs a comprehensive list of shortcuts for the Vi editor in Linux.
๐น Basic Vi Commands
Command | Description |
---|
vi filename | Open a file in Vi editor |
i | Insert mode (start editing) |
Esc | Exit insert mode |
:w | Save the file |
:q | Quit Vi |
:q! | Quit without saving |
:wq or ZZ | Save and quit |
:x | Save and quit (same as :wq ) |
:w filename | Save as a new file |
๐น Navigation Commands
Command | Description |
---|
h | Move left |
l | Move right |
j | Move down |
k | Move up |
0 | Move to the beginning of the line |
^ | Move to the first non-blank character of the line |
$ | Move to the end of the line |
w | Move to the next word |
e | Move to the end of the current/next word |
b | Move to the beginning of the previous word |
gg | Move to the beginning of the file |
G | Move to the end of the file |
ng | Move to line number n (e.g., 5G moves to line 5) |
Ctrl + d | Scroll down half a screen |
Ctrl + u | Scroll up half a screen |
Ctrl + f | Scroll forward one full screen |
Ctrl + b | Scroll backward one full screen |
๐น Editing and Inserting
Command | Description |
---|
i | Insert at the cursor position |
I | Insert at the beginning of the line |
a | Append after the cursor |
A | Append at the end of the line |
o | Open a new line below the cursor |
O | Open a new line above the cursor |
r | Replace a single character |
R | Replace multiple characters (overwrite mode) |
x | Delete character under the cursor |
X | Delete character before the cursor |
dd | Delete (cut) the entire line |
yy | Copy (yank) the entire line |
p | Paste after the cursor |
P | Paste before the cursor |
u | Undo the last action |
Ctrl + r | Redo the last undone action |
J | Join the current line with the next line |
๐น Deleting (Cut) Commands
Command | Description |
---|
dw | Delete a word |
de | Delete to the end of the current word |
d$ | Delete from cursor to end of line |
D | Delete from cursor to end of line (same as d$ ) |
d0 | Delete from cursor to beginning of line |
dd | Delete the current line |
dG | Delete from current line to end of file |
dgg | Delete from current line to beginning of file |
๐น Copy & Paste (Yank)
Command | Description |
---|
yy or Y | Copy the current line |
yw | Copy a word |
y$ | Copy to the end of the line |
y0 | Copy to the beginning of the line |
p | Paste after the cursor |
P | Paste before the cursor |
๐น Search & Replace
Command | Description |
---|
/text | Search forward for “text” |
?text | Search backward for “text” |
n | Repeat last search in the same direction |
N | Repeat last search in the opposite direction |
:%s/old/new/g | Replace all occurrences of “old” with “new” in the file |
:s/old/new/g | Replace all occurrences of “old” with “new” in the current line |
:s/old/new/gc | Replace with confirmation |
๐น Working with Multiple Files
Command | Description |
---|
:e filename | Open another file in Vi |
:bn | Go to the next buffer (file) |
:bp | Go to the previous buffer (file) |
:bd | Close the current buffer |
:sp filename | Open file in a new horizontal split |
:vs filename | Open file in a new vertical split |
Ctrl + w + w | Switch between split windows |
๐น Marks & Jumps
Command | Description |
---|
ma | Mark the current position as “a” |
'a | Jump to the marked position “a” |
| Jump back to the last cursor position |
Ctrl + o | Jump to the previous location |
Ctrl + i | Jump forward to the next location |
๐น Visual Mode (Selection)
Command | Description |
---|
v | Start visual mode (character selection) |
V | Start line selection mode |
Ctrl + v | Start block selection mode (column selection) |
y | Copy the selected text |
d | Delete the selected text |
> | Indent the selected text |
< | Un-indent the selected text |
๐น Advanced Commands
Command | Description |
---|
:set number | Show line numbers |
:set nonumber | Hide line numbers |
:set ignorecase | Ignore case in searches |
:set noignorecase | Case-sensitive searches |
:set hlsearch | Highlight search results |
:set nohlsearch | Remove search highlights |
:set wrap | Enable text wrapping |
:set nowrap | Disable text wrapping |
๐น Exiting Vi
Command | Description |
---|
:q | Quit Vi (only if no changes were made) |
:q! | Quit without saving changes |
:wq or ZZ | Save and quit |
:x | Save and quit (same as :wq ) |
๐ฏ Bonus: Vi Cheat Sheet
- Insert Mode:
i
, I
, a
, A
, o
, O
- Navigation:
h
, l
, j
, k
, w
, b
, 0
, $
- Editing:
x
, dd
, yy
, p
, P
, u
, Ctrl + r
- Search:
/text
, ?text
, n
, N
- Replace:
:%s/old/new/g
- Exit:
:q
, :q!
, :wq
, ZZ
๐ Practice These Commands
To master Vi, start practicing:
- Open a file with
vi filename
- Navigate with
h
, l
, j
, k
- Edit with
i
, a
, o
- Save with
:w
, quit with :q
- Experiment with cut (
d
), copy (y
), paste (p
)
- Search (
/text
), Replace (:%s/old/new/g
)
Let me know if you need any specific Vi commands! ๐๐ฅ
Post Views: 23