Vim: Search and Replace

:[ranges]s/{pattern}/{string}/{flags} [count]

Substitute first occurrence in the cursor line:

:s/FROM/TO/

Substitute all occurrence in the cursor line:

:s/FROM/TO/g

Substitute first occurrence in the whole file:

:%s/FROM/TO/

Substitute all occurrence in the whole file:

:%s/FROM/TO/g

Repeat the last command:

@:

ranges

.s or s = substitute on the cursor line

%s = substitute on the whole file

1s = substitute on line 1

$s = substitute on last line

1,5s = substitute on line 1 to 5

flags

g = global substitution

c = confirm before substituting

i = case-insensitive pattern matching


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *