DEV Community

Guilherme
Guilherme

Posted on

VIM - Search, Replace, Text Objects and Tags.

Same Line Search Mode:

f{char} - Forward search
F{char} - Reverse search
t{char} - move you to the next occurrence of the character afterwards
T{char} - Same as t but in reverse
; - Repeat in the same direction
, - Repeat in the opposite direction

Searching:

/{pattern} - Forward search
?{pattern} - Reverse search
n - Repeat search in the same direction
N - Repeat search in the opposite direction
* - Forward search for word where the cursor is current located
# - Reverse search for word where the cursor is current located

Substitute Command

Format:

:[range]s/{pattern}/{string}/[flags]
Enter fullscreen mode Exit fullscreen mode

Global Substitution:

:%s/{pattern}/{string}/g
Enter fullscreen mode Exit fullscreen mode

Text Object & Tags

Format:

{operator}{a}{object}
{operator}{i}{object}

Examples:

daw - Delete A Word
ciw - Change Inner Word
ci" - To change what is inside quoted strings
di[ - Delete what is inside brackets
yi< - Yank what is inside angle brackets
dap - Delete the entire paragraph
yas - Yank a sentence. A sentence is defined as ending at a '.', '!' or '?' followed by either the end of a line, or by a space or tab.

Top comments (0)