Vim and Linux Quick Reference

Commonly used Vim commands and a few essential Linux operations.


Compression

tar -czvf archive.tar.gz my_directory # Compress

tar -xzvf archive.tar.gz # Extract


Exiting

CommandDescription
:qQuit
:q!Quit without saving
:wSave
:wqSave and quit

Cursor Movement

CommandDescription
h j k lArrow keys (left, down, up, right)
Ctrl+f / Ctrl+bPage forward / backward
Ctrl+d / Ctrl+uMove down / up half a page
GGo to bottom of file
ggGo to top of file
{ / }Move forward / backward by paragraph
Ctrl+e / Ctrl+yScroll down / up one line
0Start of line
^First non-blank character of line
$End of line
%Jump between matching () or {}

Editing

CommandDescription
uUndo
Ctrl+rRedo
i / aInsert mode before / after cursor
I / AInsert mode at start / end of line

Visual Mode (Selecting Text)

CommandDescription
vCharacter-wise selection
VLine-wise selection
Ctrl+vBlock-wise selection

Clipboard

CommandDescription
yYank (copy) selected text
pPaste after cursor

Deletion

CommandDescription
dDelete (cut)
xDelete one character

Search and Replace

CommandDescription
:%s/<old>/<new>/gReplace all <old> with <new> in file
:%s/<old>/<new>/gcReplace all with confirmation
/<text>Search forward for <text>
?<text>Search backward for <text>

Commenting Out Blocks

  1. Press Esc to exit insert mode.
  2. Press Ctrl+v to enter visual block mode.
  3. Use j / k to select the lines.
  4. Press Shift+i (capital I).
  5. Type your comment prefix (e.g. % ).
  6. Press Esc twice.