Re:Difftastic, a structural diff tool that understands syntax
by joshspankit on Thursday March 21, 2024 @05:15PM
(#39784499)
How close are we to being able to copy a function in to the clipboard, then highlight some lines of code and paste the function around it (like highlight > quote marks)?
[ Parent
| on HN ]
Re:Difftastic, a structural diff tool that understands syntax
by OJFord on Thursday March 21, 2024 @08:10PM
(#39785979)
What does it mean to paste a function around some lines of code? As in what're the manual steps you do because that's not possible today?
Re:Difftastic, a structural diff tool that understands syntax
by alpaca128 on Friday March 22, 2024 @05:51AM
(#39788955)
I assume auto-wrapping a copied function signature around a selecting block as if it was just parentheses or something. I don't think I ever needed that, but a variant of that might be useful for XML where wrapping something in a pair of tags is a common operation.
Re:Difftastic, a structural diff tool that understands syntax
by joshspankit on Friday March 22, 2024 @11:07AM
(#39791462)
Mostly I would find this helpful during refactoring where it’s normal to move some code out in to a specific function. It would also be helpful for loops, if/else, validation, try/catch since you could copy the boilerplate and paste it over the code block in one move.
Re:Difftastic, a structural diff tool that understands syntax
by worksonmine on Friday March 22, 2024 @09:53AM
(#39790782)
I don't know what exactly you mean by pasting a function around the selection, but you can paste selections, registers or even files at specific lines with some vim-fu. If it's generic enough you could write a function or even a keyboard shortcut if it's very simple.
I have set ",',(,[,{ in visual mode to cut the selection insert the pairs then paste it back as a very hacky solution, but it gets the job done. If you want something more advanced to add or change anything around the selection tpope has solved that with vim-surround[1].