Normal mode *********** The default mode. Move around. Cut copy paste Mode switch =========== In Insert / Visual / Command mode, press Escape to switch back to Normal mode Moves ===== Direction Next word {Char}acter --------- --------- ----------- up word backward find till left l w e b ---> f{char} t{char} h k end <--- F{char} T{char} j right down W.rd Ba<kward place go to W E B mark mark E\d m{a-z} `{a-z} go to screen go to line ------------ ---------- start middle end bar number middle last g0 gm g$ {num}| {num}G gM G Cut, yank, put ============== x y p d{move} r{char} cut yank put delete replace with P Match ===== Cursor word # --> Pattern /<pattern> Next match n <-- Pattern ?<pattern> Prev match N Perform n times =============== {num}actions example 5dw Insert mode *********** The mode that allows typing in file Mode switch =========== In Normal / Visual mode press c / i / a / o to switch to Insert mode change before after on next line c{move} i a o C I A O line before after on previous line end line line Perform n times =============== {num}actions example 5cw Visual mode *********** Make selections in visual mode Mode switch =========== To switch to Visual mode from Normal mode v V Ctrl + v ,------ ,-----------. ,---. Selections in Selections in Selections in ----. '------ '-----------' block mode character mode line mode '---' ----' Operations ========== Cut selection x/d Yank selection y Put on cursor p Put before cursor P Command mode ************ Write commands and execute Mode switch =========== In normal (or) visual mode press : and type commands. Then press Enter to execute and go back to normal mode Open, save, edit ================ Edit Write Quit --------------- --------------- --------------- e w q e! q! e filename w filename To discard changes add ! to command Commonly used ------------- Open by filename e filename Save to file w Save to file and quit wq Save to file and quit ZZ (no going back) Quit without saving q! Tabs ==== Open tab tabnew Previous tab tabp Move tab tabmove Next tab tabn Match and replace ================= %s/<pattern>/<replacement>/<flags> Example: %s/Match/Scratch/gi Flags ----- global / all matches g case insensitive i Macros ****** start recording on 'a' qa stop recording q perform recording 'a' again @a vimrc ***** Vim can be configured with a .vimrc text file One of the default locations commonly used is ~/.vimrc Relative number =============== ----------------------------- | 3 Another line | | 2 Another line | | 1 Another line | |4 The line with the cursor | | 1 Another line | | 2 Another line | ----------------------------- To make vim show number on current line and relative number on other lines as above add to vimrc the line: set number relativenumber