DEV Community

Pavol Z. Kutaj
Pavol Z. Kutaj

Posted on

1

How to Modify Multiple Various Matches at Once in Vim

As Drew Neil instructed us in Practical Vim, it's great to decouple search (/) and Ex command (:) operating on the search.
Note: You need very magic mode to forget about escaping regex syntax!
As I am in a data wrangling mode, it's just wonderful.

Step-1: Search with a search command using very magic mode

Start search ith \/v<regex>
I need hit multiple matches.
Often terraform workspaces that failed apply during mass-rollout. I need another retry with the failed ones.
Say foo, bar and acme failed.
These can be substring of complicated names. They are unique enough.

\/vfoo|bar|acme
Enter fullscreen mode Exit fullscreen mode

Wonderful, we have the match. Now we can operate.

Step-2: Modify with an ex command

This regex pattern will match either "foo" or "bar" or "acme" strings

  • Then you can use — for example — one of my three favorites, g##d, v##d, s###g
  • :g##d — delete lines with matches
  • :v##d — delete lines without matches
  • :%s##<replace_string>#g — replace matches with

LINKS

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay