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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay