top | item 40198346

(no title)

bastijn | 1 year ago

All posts I read on VIM always compare to a barebone editor without proper refactoring plugins enabled it seems. Would love to see a proper comparison against state of the art refactoring and against a skilled user of those systems.

First one for instance with resharper plugin enabled or in any IntelliJ IDE: Ctrl R R, type new word. Bonus; replaces all instances of the variable and recognizes scope in the file so if you have two locals with the same name over two methods it would change only the one you want. You want all, multi-carrot expansion Ctrl D D until you hit what you want and replace. Multi Carret is so powerful, find a repeating pattern, can be anything and even if it occurs further down where you don’t want to change just stop hitting expansion. Sure, you can do the same with VIM but comparing VIM to modern refactoring plugins is way more fair.

Things like extract method, extract variable and replace all instances at once are also one keybind away.

discuss

order

denvaar|1 year ago

I didn't get the impression that this post was trying to compare vim to anything (which is refreshing). Seems like this is simply demonstrating how to use vim, given a few real-world editing examples.

Repulsion9513|1 year ago

You can of course get plenty of "refactor" plugins for vim out there but I've never found a need for one. Even in more complex codebases with multiple instances of a local variable like you mention, I tend to do more "find-and-replace in selection": V to Visually select a block, then just :s/foo/bar/g

jauntywundrkind|1 year ago

Generally with you

That said, many of these refactor systems are multi-file capable. Or even more fancy, they understand for example that an export is being renamed & update all consumers, leaving all other uses of that variable name as-is.

I'm a pretty mediocre but long time vim user. I don't intend to leave. But I remain interested in codemod tools that can help me reshape code at scale.

lawn|1 year ago

> All posts I read on VIM always compare to a barebone editor without proper refactoring plugins enabled it seems.

You get context aware search and replace with LSP in Vim too.

camgunz|1 year ago

Vim has substitution:

%s/thingamabob/doodad/g

You can put regexes in there, so for 99% of cases you're fine. In neovim (but not in vim) this will also show you a "multicaret" UI.

This is also just one mode of sed, so if you need to do this across multiple files you can just run sed.

lambdaba|1 year ago

Semantic stuff like refactoring is done through LSP.

t43562|1 year ago

ast-grep is a fabulous tool imo. I'm generally happier doing a large change at the commandline anyhow.