Vim

Text

  • daw delete word under cursor
  • d/cib - delete a block surrounded by (
  • d/ciB - delete a block surrounded by {
  • d/cas - delete a sentence
  • d/cap - delete a paragraph
  • Visual select the text, then U for uppercase or u for lowercase. To swap all casing in a visual selection, press ~ (tilde).

Windows

CTRL-W= equal size
CTRL-W- decreases the current window
:vsp vertically split windows
:e edit new file in current buffer
<C-^> quickly switch buffer (this and before, only 2 buffers will be loaded)

Dot .

Can be used only after text is changed

Macros

Macros | Vim Tips Wiki | Fandom
q<letter><commands>q where letter is a-z
<number>@<letter> to use

Movements

JK move 5 lines
R replace more char
HL move to beginning or end, equivalent to ^$

Indent

<G / >G to indent (. to repeat)

Tricks

  • Write as sudo

    • :w !sudo tee%
  • Set - as a word

    • set iskeyword+=-
  • Neovim Plugins

Vim Surround

Surround CommandDescription
y s <motion> <desired>Add desired surround around text defined by <motion>
d s <existing>Delete existing surround
c s <existing> <desired>Change existing surround to desired
S <desired>Surround when in visual modes (surrounds full selection)

Some examples:

  • "test" with cursor inside quotes type cs"' to end up with 'test'
  • "test" with cursor inside quotes type ds" to end up with test
  • "test" with cursor inside quotes type cs"t and enter 123> to end up with <123>test</123>