,

Vi Editor Linux Shortcut Keys

Posted by

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

CommandDescription
vi filenameOpen a file in Vi editor
iInsert mode (start editing)
EscExit insert mode
:wSave the file
:qQuit Vi
:q!Quit without saving
:wq or ZZSave and quit
:xSave and quit (same as :wq)
:w filenameSave as a new file

๐Ÿ”น Navigation Commands

CommandDescription
hMove left
lMove right
jMove down
kMove up
0Move to the beginning of the line
^Move to the first non-blank character of the line
$Move to the end of the line
wMove to the next word
eMove to the end of the current/next word
bMove to the beginning of the previous word
ggMove to the beginning of the file
GMove to the end of the file
ngMove to line number n (e.g., 5G moves to line 5)
Ctrl + dScroll down half a screen
Ctrl + uScroll up half a screen
Ctrl + fScroll forward one full screen
Ctrl + bScroll backward one full screen

๐Ÿ”น Editing and Inserting

CommandDescription
iInsert at the cursor position
IInsert at the beginning of the line
aAppend after the cursor
AAppend at the end of the line
oOpen a new line below the cursor
OOpen a new line above the cursor
rReplace a single character
RReplace multiple characters (overwrite mode)
xDelete character under the cursor
XDelete character before the cursor
ddDelete (cut) the entire line
yyCopy (yank) the entire line
pPaste after the cursor
PPaste before the cursor
uUndo the last action
Ctrl + rRedo the last undone action
JJoin the current line with the next line

๐Ÿ”น Deleting (Cut) Commands

CommandDescription
dwDelete a word
deDelete to the end of the current word
d$Delete from cursor to end of line
DDelete from cursor to end of line (same as d$)
d0Delete from cursor to beginning of line
ddDelete the current line
dGDelete from current line to end of file
dggDelete from current line to beginning of file

๐Ÿ”น Copy & Paste (Yank)

CommandDescription
yy or YCopy the current line
ywCopy a word
y$Copy to the end of the line
y0Copy to the beginning of the line
pPaste after the cursor
PPaste before the cursor

๐Ÿ”น Search & Replace

CommandDescription
/textSearch forward for “text”
?textSearch backward for “text”
nRepeat last search in the same direction
NRepeat last search in the opposite direction
:%s/old/new/gReplace all occurrences of “old” with “new” in the file
:s/old/new/gReplace all occurrences of “old” with “new” in the current line
:s/old/new/gcReplace with confirmation

๐Ÿ”น Working with Multiple Files

CommandDescription
:e filenameOpen another file in Vi
:bnGo to the next buffer (file)
:bpGo to the previous buffer (file)
:bdClose the current buffer
:sp filenameOpen file in a new horizontal split
:vs filenameOpen file in a new vertical split
Ctrl + w + wSwitch between split windows

๐Ÿ”น Marks & Jumps

CommandDescription
maMark the current position as “a”
'aJump to the marked position “a”
Jump back to the last cursor position
Ctrl + oJump to the previous location
Ctrl + iJump forward to the next location

๐Ÿ”น Visual Mode (Selection)

CommandDescription
vStart visual mode (character selection)
VStart line selection mode
Ctrl + vStart block selection mode (column selection)
yCopy the selected text
dDelete the selected text
>Indent the selected text
<Un-indent the selected text

๐Ÿ”น Advanced Commands

CommandDescription
:set numberShow line numbers
:set nonumberHide line numbers
:set ignorecaseIgnore case in searches
:set noignorecaseCase-sensitive searches
:set hlsearchHighlight search results
:set nohlsearchRemove search highlights
:set wrapEnable text wrapping
:set nowrapDisable text wrapping

๐Ÿ”น Exiting Vi

CommandDescription
:qQuit Vi (only if no changes were made)
:q!Quit without saving changes
:wq or ZZSave and quit
:xSave 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:

  1. Open a file with vi filename
  2. Navigate with h, l, j, k
  3. Edit with i, a, o
  4. Save with :w, quit with :q
  5. Experiment with cut (d), copy (y), paste (p)
  6. Search (/text), Replace (:%s/old/new/g)

Let me know if you need any specific Vi commands! ๐Ÿš€๐Ÿ”ฅ

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x