Vim

Normal Mode

. " Repeat last command "

z= " Check avalable replacement for wrong spelled "

]s " Next wrong spelled "

q: " Enter command window "

== " Indent intelligently "

gq{motion} " Reformat (rewrap) "

gqq " Reformat (rewrap) current line "

gu{motion} " Lowercase "

gU{motion} " Uppercase "

g~{motion} " Togglecase "
-
C-x " Decrement the number at the end of the word under the cursor "

C-a " Increment the number at the end of the word under the cursor "

gv " Reselect last selection "

g C-g " Show current cursor position and total counts (columns, lines, words, bytes) "

ga " Show ASCII info for character under cursor "

g8 " Show UTF-8 info for character under cursor "

C-w f " Open the file under the cursor in a split (gf will do this without the split) "

]c/[c " Next/previous change/conflict "

Movement

h, j, k, l " Per-character/per-line movement through file (left, down, up, right) "

gj, gk " Per-line movement through buffer, operating on display lines (which may be wrapped) not actual lines in the file (down, up) "

w " Forward a word (mnemonic: 'word'); here 'word' is an 'keyword' (identifier) like 'foo9' or 'hgo' and the movement is to the _beginning of the next word "

W " Forward a 'big' word; here a 'word' is anything other than whitespace "

b " Back a word (mnemonic: 'back'); again the movement is to the beginning of the word "

B " Back a 'big' word "

e " Forward to the end of a word (mnemonic: 'end') "

E " Forward to the end of a 'big' word "

ge " Back to the end of the last word "

gE " Back to the end of the last 'big' word "

f{character} " Forward to the next occurrence of character (mnemonic: 'find/foward') "

F{character} " Same as f{character}, but search in the opposite direction "

t{character} " Forward til (until) the next occurrence of character (mnemonic: 'til/to'); the cursor is place immediately before and not on the character "

T{character} " Same as t{character}, but search in the opposite direction "

; " Repeat last f, F, t or T operation "

, " Repeat last f, F, t or T operation, but in the opposite direction "

C-f " Forward a (full) screen (mnemonic: 'forward') "

C-b " Back a (full) screen (mnemonic: 'back') "

C-d " Down a (half) screen (mnemonic: 'down') "

C-u " Up a (half) screen (mnemonic: 'up') "

H " Jump to top of screen (mnemonic: 'high') "

M " Jump to middle of screen (mnemonic: 'middle') "

L " Jump to bottom of screen (mnemonic: 'low') "

gg " Jump to top of file (mnemonic: like more or less pagers, except plain g isn’t available so we have to use gg) "

G " Jump to bottom of file (mnemonic: like more or less pagers) "

200G " Jump to line 200 "

:200 " Same as 200G "

{ " Jump to last blank line "

} " Jump to next blank line "

[[ " Jump to previous { in column 0 "

]] " Jump to next { in column 0 "

][ " Jump to next } in column 0 "

[] " Jump to previous } in column 0 "

% " Jump to matching brace (with matchit.vim you can also jump to matching HTML tags and the like) "

]s " Jump to next misspelled word "

zg " Mark a word as good, adding it to the spelling dictionary "

Scrolling

zz " Center current cursor line within viewport "

zt " Scroll current cursor line to top of viewport "

zb " Scroll current cursor line to bottom of viewport "

C#-y " Scroll down a line "

C-e " Scroll up a line "

C-d " Scroll down one page "

C-u " Scroll up one page "

Autonumbering Several Lines

  1. Type “1.” in every line.
  2. Select all of them with visual block. (<C-v>)
  3. g<C-a> for ascending g<C-x> for descending

Insert Mode

C-o " Switch from insert mode to normal mode just for one normal mode command "

C-w " Delet to the beginning of current word "

C-t " Indent current line "

C-d " Dedent current line "

C-v<tab> " Insert a hard tab when it normally expands to spaces "

C-r% " Insert current filename "

Command Mode

:map " Give a list of user-defined mappings "

:help index " Give a full list of mappings "

:help map-witch-keys " Give a list of all unmapped keys "

:help index " Give a full list of mappings "

:help map-witch-keys " Give a list of all unmapped keys "

:helpgrep {pattern} " Search all help documents for pattern  "

:earlier 5m " Go backward 5 minutes in time "

:later 5m " Go forward  5 minutes in time "

:setlocal spell! spelllang=en_us " Set spell checker "

:set ic " Case insensitive "

:set hlsearch " Highlight search "

:m,n bw " Wipe m-n buffers "

:bd pattern " Search a pattern in buffers to delete "

:buffers " Show all buffers "

:nohlsearch (:noh) " Remove currently visible search highlighting (doesn’t disable highlighting permanently) "

:enew (:ene) " Open a new scratch buffer "

:write " Write current buffer to a file "

:read " Read into current buffer; eg:  "

:read !{shell command} " Insert output of shell command into current buffer at current cursor location "

:{range}d " Delete lines in {range} "

:{range}y " Yank lines in {range} "

:g/{pattern}/{action} " Perform action on lines matching pattern (eg. :g/a/d would delete all lines matching "a") "

:v/{pattern}/{action} " Inverse of :g (performs action on non-matching lines) "

:echo expand("%") " Show the current buffer PATH "

:w !sudo tee % " Write to a read only file with root privileges "

command-line Window

To open the command-line window (showing full command history in a buffer, which you can edit, then use to run a given line’s command):

q: " For commands "

q/ " For searches (or q?) "

Quickfix/Location List

:cclose (:ccl) " Close quickfix window (:lclose and :lcl for location list) "

:colder (:col) " Show previous quickfix results (:lolder and :lol for location list) "

:cnewer (:cnew) " Show subsequent quickfix results (:lnewer and :lnew for location list) "

Marks And Jumps

When jumping to a mark, there are two variants:

with ', the jump is line-wise, to the first non-blank character on the line containing the mark

with `, the jump is character-wise, to the position of the mark within the line

m{letter} " Create a mark at the current position "

'{letter} " Jump to specified mark (first non-whitespace character on line) "

`{letter} " Jump to specified mark (to column where mark was set) "

'' " Jump back to the last line jumped from "

`` " Jump back to the last position jumped from "

`. " Jump to position where last change occurred in current buffer "

`[ and `] " Jump to beginning/end of last changed or yanked text "

`< and `> " Jump to beginning/end of last visual selection "

:jump " Show the jump list (places you’ve jumped to with motion commands, specifically those listed at :h jump-motions) "

C-o " Move to older position in jump list (mnemonic: "jump out") "

C-i: " Move to newer position in jump list (mnemonic: "jump in") "

:changes " Show the changes list for the current buffer (places you’ve edited) "

g; " Move to older position in change list "

g, " Move to newer position in change list "

Folding

zr " Decrement 'foldlevel' A.K.A. 'fold less' (mnemonic: reduce) "

zm " Increment 'foldlevel' A.K.A. 'fold more' (mnemonic: more) "

zR " Decrement 'foldlevel' to zero A.K.A. 'unfold everything' (mnemonic: reduce) "

zM " Increment 'foldlevel' to maximum A.K.A> 'fold everything' (mnemonic: more) "

zo " Open current fold "

zO " Open current fold recursively "

zc " Close current fold "

zC " Close current fold recursively "

zv " View cursor line A.K.A. 'open just enough folds to make cursor line visible' (mnemonic: view/visible) "

zi " Toggle value of 'foldenable' (mnemonic: invert) "

#Visual Mode Commands

Enter using V:

gq " Reformat (rewrap) selection "

o " Jump to opposite end of selection "

Visual (block) Mode Commands

Enter using :

$A{string}<Esc> " Append to each line, varying lengths (details). "

Mappings

CTRL-w Enter " Open current item in a split. "

Mappings Available in Command Mode

<C-r>{register} ' Paste the text from the specified register into the command line (eg. to paste the last-yanked text, do <C-r>")  '

<C-r>w " Paste word currently under cursor "

Special Mappings

<C-w><CR> " Open quickfix entry in a horizontal split "

Global Commands

:g/var[A-Z]\+[0-9]/norm_da(0P " Delete around () in any line that has var'any sequence of a-z''any sequence of 0-9' pattern and paste in in the beginning of the line "

:12read !{a shell command} " Read the output of shell command and insert that into document after line 12(use $ for the end of document) "

:g/pattern/command " Run the command on every line that included the pattern (use g! or v for reverse) "

:g/^\s*$/d " Delete all empty lines "

:g/pattern/t$ " Copy every line that has the pattern in it and paste them at the end of document (use m$ for moving those lines) "

:g/^/m0 " Reverse the line order in document "

Diff

[c " Jump to previous change "

]c #jump to next change 

do #diff optain

dp #diff put

zo #open folded text

zc #close folded text

za #toggle

zv #open folds for this line

zM #close all

zR #open all

zm #fold more (foldlevel+=1)

zr #fold less (foldlevel-=1)

zx #update folds

:diffupdate #update diffs

Search

* " Find word under cursor "

# " Find word under cursor (reverse direction) "

g* " Like *, but also looks for matches which are substrings of other words "

g# " Like #, but also looks for matches which are substrings of other words "

/{pattern} " Find pattern (mnemonic: like Perl/Ruby/pager etc regex syntax) "

?{pattern} " Find pattern (reverse direction) "

n " Repeat last search "

N " Repeat last search in opposite direction "

gn " Go to next match and select it visually; can be used as a motion as well (ie. cgn means "change next match") "

ggn " Go to first match in file "

Gn " Go to last match in file "

Ranges And Patterns

$ " End of the document "
. " Current line "
^ " Beginning of line "

vim commands

vim -esu NONE +'g/\v^(.*)\n\1$/d' +wq # Delete duplicate, consecutive lines from a file

vim -esu NONE +'g/\v^(.+)$\_.{-}^\1$/d' +wq # Delete duplicate, nonconsecutive and nonempty lines from a file

My Vim (Nvim) Config