Vim

22 Aug 2021 | computer

General

Tip: Run vimtutor in a terminal for a basic Vim tutorial.

Cursor Movement

Tip: Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines.

Inserting/Appending Text

Editing

Marking Text

Tip: instead of b or B one can also use ( or { respectively.

Visual Commands

Registers

Tip: Registers are being stored in ~/.viminfo, and will be loaded again on next restart of vim.

Tip: Special registers: O : last yank ": unnamed register, last delete or yank %: current file name #: alternate file name *: clipboard contents (X11 primary) +: clipboard contents (X11 clipboard) /: last search pattern :: last command-line .: last inserted text -: last small (less than a line) delete =: expression register _: black hole register

Marks and Positions

Tip: To jump to a mark you can either use a backtick (```) or an apostrophe ('). Using an apostrophe jumps to the beginning (first non-blank) of the line holding the mark.

Macros

Cut and Paste

Indent text

Exiting

Search and Replace

Search in Multiple Files

Tabs

Working with Multiple Files

Diff

Tip: The commands for folding (e.g. za) operate on one level. To operate on all levels, use uppercase letters (e.g. zA).

Tip: To view the differences of files, one can directly start Vim in diff mode by running vimdiff in a terminal. One can even set this as git difftool.