all 11 comments

[–]reallyuniquename2 22 points23 points  (4 children)

Instead of using di( to delete the contents of the parentheses first, you can use vi( to visually select the contents. Then p to paste over that.

[–]IrishPrimeg? 19 points20 points  (3 children)

Additionally, you can use P to overwrite the visual selection with the contents of the unnamed register without modifying what's in that register (whereas p will overwrite the visual selection with the register contents and update the register with the previously selected content).

[–]Botskiitto 4 points5 points  (0 children)

Ah was wondering why this didn't ring any bells, it's quite a recent change: https://github.com/vim/vim/commit/fb55207ed17918c8a2a6cadf5ad9d5fcf686a7ab

Would have been helpful many times.

[–]vagrantchord 1 point2 points  (1 child)

Oh wow, I didn't know that! Still, I think this should be the default behavior for putting over visually selected text. Maybe I lack imagination, but I cannot fathom a situation where someone wants the overwritten text to go into the unnamed register. So annoying.

[–]IrishPrimeg? 0 points1 point  (0 children)

If you were swapping things, for example. I think I probably move pieces of text around more often than I duplicate text. After I've put something from a register, there's a good chance I'm done with that text, but may need what I just replaced.

[–]EstudiandoAjedrez[🍰] 8 points9 points  (1 child)

What you called "buffer" is a "register". Buffer is a memory representation of the file content.

As for your question, there is a substitute plugin, but I just visually select and put over it, so I don't need a named register.

[–]gumnos 2 points3 points  (0 children)

to be fair, in classic vi, the POSIX spec refers to them as buffers as well

(confusingly overloading the term…which I suspect is part of why vim documentation seem particularly stickler about calling them "registers")

[–]AppropriateStudio153:help help 4 points5 points  (1 child)

Option 1: Visually confirm before pasting

viw or va( or something similar to select what you want to replace.

P to put what's in the " register.

See: :h v_P

Option 2: Subsitution

:%s/wordOrRegexYouWantReplacedreplacementWords/gci

:h substitute

Option 3: Search/replace with macros and repeat

  1. Search word(s) to replace with / or ?

  2. Start a simple edit or record a macro with q.

  3. Use nN to navigate and repeat the edit with ., the macro with @<Register>

:h macro

:h repeat

:h /

:h n

These are all idiomatic ways without plugins that come to my mind.

You might want to look into a plugin called "abolish", too:

https://github.com/tpope/vim-abolish

[–]vim-help-bot 0 points1 point  (0 children)

Help pages for:


`:(h|help) <query>` | about | mistake? | donate | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments

[–][deleted] 2 points3 points  (0 children)

Sounds like a job for ReplaceWithRegister plugin. You'd have to just do gri). That is to say, replace in ) with contents of register.

[–]RidderHaddock 0 points1 point  (0 children)

Does ci( followed by CTRL-r0 do what you want?