D   A   T   A   W   O   K





Creation: December 28 2015
Modified: February 05 2022

VIM REFERENCE

Basic Movement

Insertion & replace -> insert mode

Commands and Movements

<command> <movement>

Examples:

5B moves back five words,
2w moves forward two words

Commands

i : insert before cursor
a : insert after cursor

d[n movement] : delete (~cut)
D : delete to the end of line (equals to d$)

y[n movement] : yank (~copy)

p : put text after the cursor position /put line after current line P : put text before the cursor position / put line before current line (if you put an entire line, th

c[n movement]: change, similar to delete but enters insert mode C : change to the end of line (equals to c$)

[n]r: replace [n] characters with another one R: enter replacement mode

[n]x: delete [n] characters from the cursor [n]X: delete [n] characters before the cursor

[n]s: substitute, apparently just deletes n characters and enter in insert mode.

i,a,c,s: leaves the user in insert mode

[n]~ : change chase of n characters

Special commands

cc: replace the entire current line dd: delete the entire current line yy: yank a line

. : repeat the last command

--- Movements ---

h,j,k,l: word the cursor left, down, up, right

w: move to the start of the next word W: like w but skips symbols and punctuation b: move to the start of the previous word B: like b but skips symbols and punctuation e: move the the end of the word E: like e but skips symbols and punctuation

G: goto end of file nG: goto line n

Special Positions: $ : end of line 0 : start of line you can repeat a command to the end of line

x : remove a character under the cursor X : remove a character before the cursor

u : undo the last command (vim supports "infinite" undo) U : ?

--- Special Combos ---

'y' and 'p' : copy and paste 'd' and 'p' : cut and paste 'x' and 'p' : swaps two characters

--- Mapping Keys ----

'map seq1 seq2': maps the sequence 1 to the sequence 2 'unmap seq1' : unmap the sequence 1 (if exists)

Example: map ciao dd - in command mode 'ciao' is synonim of 'dd'

VI special sequences are mappable.

--- Splitting ---

'sp' : open a file and horizontal split 'vs' (or 'vsp') : open a file and vertical split CTRL+W,CTRL+W: goto the next pane CTRL+W,Arrow: goto next pane

Searching

To search for a pattern, in command mode, append the search pattern to the / character

/pattern

In case of pattern match use "n" to move to the next match and "N" to move to the previous match.

After searching, an empty search pattern will repeat the last search. This works with /, :s, and :g.

So, after searching for a word, use :%s//new/g to change all occurrences to 'new', or :g/ to list all lines containing the word.

Extra Notes

In general an uppercase letter means Before, a lowercase one means After

Tips

Justify to 75 columns:

set textwidth=75
gqG

Links

Proudly self-hosted on a cheap Raspberry Pi