Question

Does anyone know of a pre-existing technique to edit multiple lines in VIM using Marks or something similar? I use Shift+I / Shift+A when visually selecting columns to insert before and after, it would be nice to something similar with "uneven" or "Jagged" lines.

Example of "Jagged" Lines:

<a href="new/link/"> same link </a>
<a href="new/link/to/another/area/"> next link </a>
<a href="old/link/same/content/"> same size </a>
<a href="interesting/tmp/same/info/"> size same </a>
<a href="to/a/great/place/known/the_same/"> what link </a>
<a href="another/new/link/"> this link </a>
<a href="into/links/"> some link </a>

In this example, I'd want to adjust the internal text of the link: "same link", "next link", "same size" etc.

This could easily be done with a regular expression, but would also be nice if it could be done with marks somehow.

Example Workflow:

  • Go to begining of each similar sized item to edit
  • Mark with '[a-z,A-z] etc.
  • :MarkInsertMode # << Something Similar to this, ideally mapped
  • Then it works just as Shift+A or Shift+I, editing shows on single line and updates on all lines

Most likely if there are no answers for this one I'll be writing a script to do it, but I'm curious if anything like this is out there so far.

Was it helpful?

Solution

The vim-multiple-cursors plugin was already mentioned in the comments. If the text you're editing is identical, an alternative is my ChangeGlobally plugin; which provides a new gc command that works like built-in c, but after leaving insert mode applies the local substitution to all other occurrences.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top