To create new classes and data-related objects I find myself often doing the following pattern -- where I copy paste a 'base line' and then I need to update one or two values, for example:

enter image description here

Here is a 10s video of how I'm currently doing it -- https://gyazo.com/25589f74c7adac3c581442354ca9c502

What would be the best way -- keeping alignment -- to change the "error_msg" value in the below two places? Also, the problem with a regex approach is (as far as I'm aware) it doesn't respect alignment when it does the 'replace' if the strings have a different size, so that creates another issue if I use that approach, where I have to tab/space things out at the end every time which becomes a bit tedious.

  • 1
    (Comment bc i dont align) Personally, I (a) yy and then paste as many times as I need, doing :s/word/repl/g on the first and :s//repl/g on the remaining, (b) write a macro, or (c) write a function/command/script (vim or otherwise) to generate the code. I don’t align (too much hassle, 0 benefit for me), but there are plugins that make it easier. I suppose snippets is an option too, but that doesn’t solve alignment – D. Ben Knoble Oct 30 '20 at 13:24

Your Answer

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

Browse other questions tagged or ask your own question.