3 ms·
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 > quot
by joshspankit 3y ago
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)?
- OJFord 3y agoWhat 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?
- alpaca128 3y agoI 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.
- joshspankit 3y agoMostly 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.
- worksonmine 3y agoI 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]. [1]: https://github.com/tpope/vim-surround https://github.com/tpope/vim-surround