Vim
vim essentials !
General
ESC
/CTRL+c
: Command Mode:q
: Quit:q!
: Quit WITHOUT Saving:wq
/:x
: Save and Quit:w new_file_name
: Save content to a new_file_name:#,#w new_file_name
: Save content starting from # to # to new_file_name
Navigation
Character
h
: Leftl
: Right
Line
j
: Downk
: Up:#
/#G
: Jump to line Number #0
/^
: Jump to Beginning of the line$
: Jump to end of the line
Word
w
: Next Word(Beginning)e
: Next Word(End)b
: Previous Word(Beginning)
Sentence
)
:Jump to Beginning of next sentence(
:Jump to Beginning of previous sentence
Paragraph
}
: Jump to Beginning of next paragraph{
: Jump to Beginning of previous paragraph
Page
G
: Jump to end of the documentgg
: Jump to start of the documentCTRL+f
: Scroll Next PageCTRL+b
: Scroll Previous Page
Inserting
i
: Insert before cursorI
: Insert at the beginning of the linea
: Insert after the cursorA
: Insert at the end of the lineo
: Insert a new line below the cursorO
: Insert a new line above the cursor:r file_name
: Insert the externalfile_name
content at the cursor location:#r file_name
: Insert the externalfile_name
content at the line no #
Editing
Cut, Copy & Paste
d
: delete the Characterdw
: delete start of next wordde
: delete till end of current worddd
: delete whole lined)
: delete rest of the sentencedt?
: delete until ?y
: copy the selection charactersy)
: copy rest of the sentenceye
: copy still end of current wordyy
: copy the while linex
: cut Characterp
: paste the selection/copied after the cursor
Selection
v
: enter selection modeV
: select lineCTRL+V
: block selection
Replace
r
: replace charactersc
: replace entire linecw
: change word and delete to insertce
: replace rest of the wordc)
: replace rest of the sentencecc
: replace whole linect?
: delete until ? and replace withc$
: delete until the rest of the line
verb-modifier-object
Verb | Modifier | Object |
---|---|---|
v (visual) | i (insert) | w (word) |
c (change) | a (around) | s (sentence) |
d (delete) | t (till) | p (paragraph) |
y (yank) | f (find) | b (block) |
t (tag) |
ciw
: change current wordct<CHAR>
: delete untildiw
: delete current wordc/foo
: change until next occurrence offoo
Undo, Redo & Repeat
u
: UndoCTRL+R
: Redo.
: repeat the last command
Searching
/pattern
: search pattern in forward direction?pattern
: search pattern in the backward directionn
: jump to next occurrenceN
: jump to previous occurrence
Search and Replace
:s/old/new/g
: replace old with new:#,#s/old/new/g
: replace old with new from line number # to line number #:%s/old/new/gc
: replace old with new with prompt in whole file
Miscellaneous
Jumps
Ctrl+i
: move to next instance in jump listCtrl+o
: move to previous instance in jump list%
: jump to pair of the bracketjumps
: list all the jumpsShift+G
: show current file locationszz
: move the cursor to middle of window
Register
"ay
: copy to register a"ap
: paste from register a:reg
: see list of registers
Macros
qa
: record macro aq
: stop recording macro@a
: run macro a@@
: run last macro again
Marks
m[a-z]
: mark text using character mode (from a to z)M[a-z]
: mark lines using line mode (from a to z)'a
: jump to position marked a'.
: jump to the last edit:marks
: list all the marks
Split view
:sp
/Ctrl+ws
: split view (open new window/ same buffer) Horizontal:vsp
: split verticallyCtrl + ww
: switch between windowsCtrl + wc
: close windowCtrl + h/j/k/l
: navigating between the splits
Buffers
:e file
: edit file in new buffer:e!
: reload file from discCtrl+g
: show file name and cursor location:ls
: see list of all buffers:bn
: move to next buffer:bp
: move to previous buffer:b file
: move to a specific buffer “file”:b #
: move to buffer number #
Tabs
:tabnew
: open new tab:tabnew file
: open file in new tab:tabn
: next tab:tabp
: previous tab
Set Options
:set nu
: enable line numbers:set rnu
: enable relative line numbers:set rnu!
: disable relative line numbers:set nonu
: disable line numbers:set ruler
: enable the file ruler:set autoindent
: autoindent:set expandtab
: expand tab to spaces:set shiftwidth=4
: when shifting indent with 4 spaces:set tabstop=4
: when tabbing indent with 4 spaces:set hlsearch
: enable search highlights:set ignorecase
: ignore search case:set incsearch
: Incremental search with partial matches