- Verbs (actions)
d: deletec: changey: yank (copy)v: visually select char (Vfor full line)
- Modifiers (before nouns to describe how to do something)
i: insidea: aroundNUM: number (e.g. 1, 2, 10)t: search for something and stop before itf: search for something and land on it/: find a string (or regex)
- Nouns (objects)
w: wordsor): sentencepor}: paragrapht: tag (HTML/XML)b: block
- Order: VMN (verb, modifier, noun)
d2w: delete 2 wordsdt.: delete everything until next periodcis: change inside sentence (replace current full sentence)yip: yank inside paragraph (copy paragraph you are in)yt;: copy to next semicolonct(: change to open parenthesis
- Save & exit
:wqZZ(no colon)
- Search
/{string}: search for {string}t: jump up to a charf: jump onto a char*: search for other instances of word under cursorn: go to next instance of search stringN: go to previous instance of search string;: go to next instance of a char (use aftertorf),: go to previous instance of a char (use aftertorf)K: grep for files containing the word under cursor (requires silver_searcher)
- Move
- Basic
j: move down one linek: move up one linel: move left one charh: move right one char
- Line
0: move to beginning of line^: move to first non-whitespace char of line$: move to end of line
- Word
w: move forward one word (to beginning)W: move forward one big word (e.g. with -, /, etc.)b: move backward one word (to beginning)B: move backward one big word (e.g. with -, /, etc.)e: move to end of current/next word
- Sentence/paragraph
): move forward one sentence}: move forward one paragraph
- Screen
H: move to top (high)M: move to middleL: move to bottom (low)gg: go to top of fileG: go to bottom of file^U: move up half a screen^D: move down half a screen^F: page down (forward)^B: page up (backwards)^E: scroll up one line^I: scroll down one line
- Jump
^i: jump to previous navigation location^o: jump back to where you were30G: jump to line # 30:30: jump to line # 30
- Basic
- Change/insert (all enter Insert mode)
i: insert before the cursora: append after the cursorI: insert at the beginning of the lineA: append at the end of the lineo: open a new line below the current oneO: open a new line above the current oner: replace only the char under the cursorR: replace the char under the cursor and following untilEscc{m}: change whatever you use as a movement{m}(e.g.w,$)C: change current line (from cursor to end of line)s: substitute from cursor to next command (noun) [doesn't work?]S: substitute current line~: change case (toggle)
- Format
gq ap: format around paragraph (ap) according totextwidthsetting!}fmt -w 72: format paragraph (}) to be 72 chars wide (can be line ($), sentence ()), etc.)
- Delete
x: exterminate char under cursorX: exterminate char before cursord{m}: delete whatever you use as a movement{m}(e.g.w,})dd: delete current lineD: delete to end of lineJ: join current line with next one (delete what's b/w)
- Undo/redo (can use repeatedly to go back or forward)
u: undo last action^r: redo last action
- Repeat
-
.: repeat last action (edit command?)dw # *delete* a *word* 5. # delete 5 more words/delinquent # search for a word A[DO NOT PAY] [Esc] # *append* text to end of line n. # repeat on all other instances -
&: repeat lastexcommand?
-
- Copy/paste
y: yank selected textyy: yank current line- cutting is the same as deleting (deleted text is stored into a buffer)
p: paste copied (or deleted) text after the cursor positionP: paste copied (or deleted) text before the cursor positionddp: swap current line with next
"*yy: copy to sys register/clipboard"*p: paste from sys register/clipboard (need+clipboardand maybe+xterm_clipboard)vim --version: check optionsvimis compiled with
- Spell check
:set {no}spell: enable/disable spell check:setlocal spell: enable spell check?]s: go to next misspelled word[s: go to last misspelled wordz=: get suggestions for a misspelled word (when over it)zg: mark a misspelled word as correctzw: mark a good word as misspelled^N: next auto-complete in insert mode only (set complete+=kspell)^P: previous auto-complete in insert mode only (set complete+=kspell)
- Substitution
:%s /foo/bar/g: substitute all foo with bar on every line:s /foo/bar/g: substitute all foo with bar only on current line:%s/^/this/g: insert 'this' at the beginning of every line:%s/$/this/g: insert 'this' at the end of every line:1,^s/foo/bar/g: replace all 'foo' with 'bar' from line 1 to the start of the current linegis for all instances in a file (:%s) or a line (:s) (global)cis for confirmation:%s/|/[Ctrl+V][Ctrl+M]/g: substitute all|with new lines
- Text objects (perform actions/verbs against complex targets/nouns)
iw: inside word (doesn't get spaces)aw: around word (gets spaces around)daw: delete around word
is&as: sentencescis: change inside sentence (delete entire sentence and get in Insert Mode)
ip&ap: paragraphsi'&a': single quotesi"&a": double quotesci": change everything inside double quotes (change only thing in quotes)ca": change everything around double quotes (replace full quoted object)- edit HTML URL link
ci": change link in quotescit: change link tag?
i`&a`: back ticksi(&a(: parenthesisi[&a[: bracketsi{&a{: bracesit&at: tags
- Visual mode
v: char-basedV: line-based^V: paragraphs
- dos to unix
:update
:e ++ff=dos
:setlocal ff=unix
:w
- Vundle
:SyntasticInfo: check syntastic status:BundleList: list of bundles:BundleInstall!: force update of bundles
- vim-plug
:PlugInstall:PlugClean:PlugUpdate
-
Replace spaces with tabs
:retab!:%s/^\([^I]*\) /\1^I/g: bad?
-
Replace tabs with spaces
:retab
-
Change indentation from 2 to 4 spaces
- First convert spaces to tabs
:set ts=2 sts=2 noet :retab!- Then convert tabs to spaces
:set ts=4 sts=4 et :retab
- Comment N lines using visual block mode [Best]
^V # enter visual block mode
j # scroll down N lines
l # if uncommenting multi-char types (e.g. //)
I # insert (comment)
// # comment type
# # or this comment type
d # or delete (uncomment)
x # another delete
Esc # small delay after
:.,+N-1 s/^/#/g: comment N lines:%s/^/#/g: comment every line in a file:5,10s/^/#: comment lines 5 through 10
:set nu: show line numbers