0

a weird question that i can't seem to solve

i want to do a search and replace,

anything that says

%d, %3d, %13d

or anything like that i want to replace it with XXX I'm not sure how to deal with any arbitrary number of numbers in between % and d.. is there anyway i can do this? for even something absurd like

%000010d

I have tried to go about something like

%s/%...\dd\|%..\dd\|%.\dd\|%\dd\|%d/XXX/g

to try and solve it each case at a time but I figured there's a better way to do a search and replace.. Thanks in advance!

  • 2
    @JimStewart You should write that as an answer. – Karl Yngve Lervåg Sep 20 '17 at 6:40
  • @JimStewart If you added it as an answer we could upvote it so you can start earning the rep you need to close it ;) (I mean literally just paste it in: it's concise, but it fully answers the question.) – Rich Sep 20 '17 at 20:11
  • @solobyy you might have a look here to familiarize yourself with some of things that vim regex can do. – Tumbler41 Sep 20 '17 at 20:39
3

This will match any number of digits before the d:

:%s/%\d*d/XXX/g

\d matches any digit, * matches 0 or more times.

See :h pattern.txt for all things regex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.