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

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

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