- Last update:

Vim Tricks

A few tricks for Vim that I have learned over all my years of using this incredible tool.

🕒 4 min read

Category: Linux

Tags: vim, vi, linux

Left-right and up-down motions

Text objects motions

Text objects (only in visual mode or after an operator)

Copying and moving text / Inserting text


General rule: [optional number to repeat]{command}{text object or motion}.


Autocomplete (in insert mode)

(^n is disabled by YouCompleteMe.)


Interactive find and replace


% means whole document, not just the current line.

/g means every occurence, not just the first one. /c is the interactive option.

Capturing groups


Will print kodefok.

Normally, to search in a non-greedy way, we add a punctuation mark, as in .*? which means any string of characters as short as possible. For instance:


Applied to the string abc<p>def<a>ghi<b>jkl would match <p>def<a> and capture def. To make non-greedy searches with Vim, replace *? with \{-}.


Split the screen in half and display two different parts of a given file

:set scrollbind

Then, on the right pane, scroll down or up, further in the file, and do:

:set scrollbind

From that point on, as you scroll on one pane, the other one will follow. To undo:

:set noscrollbind


Useful links