Hind Forsum
Hind Forsum

Reputation: 10507

vim: how to replace ":" in a pattern without removing all ":"?

I've got this python-like text:

if a==0:
   print ok
   [1:]xy

I wish to delete all "[1:]" content. So I tried this:

%s/[1:]//g

Unfortunately, the first line is changed to be

if a==0

The ":" was eliminated, not as my expectation. So how should I do?

Upvotes: 0

Views: 47

Answers (2)

Volodymyr Kononenko
Volodymyr Kononenko

Reputation: 508

Escape square brackets, like this:

%s/\[1:\]//g

Upvotes: 2

m0tive
m0tive

Reputation: 2946

Vim search uses regular expressions to match, [ and ] are special characters in regex to match sets of characters.

[1:] means 1 or :. You need to escape the brackets like: %s/\[1:\]//g

Upvotes: 4

Related Questions