0

I need to highlight multiple words that are unrelated, eg:

aaa bbb
ccc ddd

I would like to highlight aaa and ddd, and keep cursor at both of those words,
so when I try to change the word for example cw, it does for both of them. I want to be able to do this without plugins.
Because somehow internal functions of some plugins don't work with macros.

There is this beautiful plugins, that does exactly what I need, but it doesn't work with macros.

EDIT (from comments): Let's say for example I want to change an HTML tag with it's corresponding closing tag. The only way to do that with a macro is to put a cursor at them both so you can operate on them.

The transition between a tag and a closing tag is easily done with a %.

Now the problem with that article is that, imagine you have nested tags with the same name, there would be a problem when searching.

This is a gif of what I'm trying to achieve with macros:

html with nested tags

  • By "highlight", do you mean "search", in one go? If so, I think you'll need a regular expression that matches the words you want, so that you can operate on them. – Biggybi May 15 at 17:33
  • Welcome to Vi and Vim! Regarding your question, I don't think it's possible to do what you ask without using plug-ins, since Vim doesn't have any "multiple cursor" feature out-of-the-box... In fact, macros are typically a way Vim users solve these problems without using multiple cursors, by recording a macro and replaying it for each word, one at a time. See, for example, this article "You don't need more than one cursor in vim". – filbranden May 15 at 17:54
  • thanks @Biggybi @filbranden, lets say for example i want to change an html tag with it's corresponding closing tag. the only way to do that with a macro is to put a cursor at them both so you can operate on them. the transition between a tag and a closing tag is easily done with a %. Now the problem with that article is that, imagine you have nested tags with the same name, there would be a problem when searching. this is a gif of what i'm trying to achieve with macros. i.imgur.com/G0A61QR.gif – Yassine Bridi May 15 at 18:44
  • @YassineBridi See question "Is there an instant way of editing matching inner tags?" – filbranden May 15 at 18:52
  • 1
    That's great, i didn't know about jumping back the last location. that would solve my whole problem, thanks. – Yassine Bridi May 15 at 18:59
0

I don't think it's possible to do what you ask without using plug-ins, since Vim doesn't have any "multiple cursor" feature out-of-the-box. Nor is it possible to use Vim's Visual or Select modes to visually select more than one area of text at the same time.

There are plug-ins that implement "multiple cursors" on Vim. But as you've noticed, they tend to have restrictions on what Vim features are available when using a multiple selection, and it doesn't surprise me that they would not allow macros to be replayed...

Vim power users typically employ different mechanisms to efficiently perform the kind of editing that usually benefit from "multiple cursors" on editors which have first-class support for that feature.

See, for example, this article "You don't need more than one cursor in vim", which makes this point quite well.

In the comments, you mentioned the specific case of updating HTML tags with their corresponding close tag (while possibly having nested instances of the same tag pair inside it.)

For that particular situation, see question "Is there an instant way of editing matching inner tags?", which also covers that exact situation well with a few approaches that are pretty efficient in Vim, some of which don't really require any external plug-ins.

| improve this answer | |
  • 1
    If things are as simple as in the example text, visual-block may help – D. Ben Knoble May 16 at 13:52
  • 1
    There is no way a visual block, would achieve what's in the gif. – Yassine Bridi May 16 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.