3
votes

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.

1
You might try this plugin vim-multiple-cursors. It looks like it should do what you want using multiple visual selections. - FDinoff
can you explain why you want to use "marks" to do that over :s/../../? :s is so straightforward. also you could record a macro to do that too, but I would use :s if I were you. or I didn't understand your requirement? - Kent
I currently use the sed expressions to edit my lines, but it's non-ideal, steps you out of the moment to think of a regular expression while editing. - Vita Pluvia
Thanks FDinoff! That looks great, I'll check it out, if it's as advertised in those beautiful gifs, this should do the trick! - Vita Pluvia
@VitaPluvia Tell me how it goes. (But I only recommended it because the gifs looked like what you wanted. I've never used the plugin) - FDinoff

1 Answers

1
votes

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.