Wrestling with large code amounts and winning: multi-line editing

By | September 20, 2017

Sometimes on the data processing project, it is needed to work with a large amount of code or other text which is similar but still is different enough. So, it is not viable to extract it into the callable function. For example (yes it is contrived one) you might have a long list of object initializers like this:

Imagine for some reason you decided you wanted to make Student immutable and now you need to replace object initializers with constructor calls. Such a task sounds daunting and extremely boring (unless there is Resharper’s feature that can do exactly what you want). Watch what is possible with Visual Studio Code. It saved me so much time in my last projects where I had to write tones and tones of DSL code to specify domain object definitions:


Here is what I did (Windows 10):
1) Ctrl+F to search for,}; which is just an anchor for VS Code to know what to highlight;
2) Alt+Enter to give a cursor to each highlighted piece of code;
3) I replace right curly bracket with round one and delete unneeded space;
4) Ctrl+Left Arrow to navigate word by word to the left (in general all shortcuts to navigate text are very useful in this context because cursors may be in different places of the lines);
5) I replace left curly bracket with round one and delete unneeded code Name=.
6) Escape to remove multi-line cursor. Done!

Additionally, to add cursors, you can hold Ctrl+Alt while pressing the up ↑ or down ↓ arrow keys or hold Alt and click left mouse button in desired spots. But using search/Alt+Enter feature can make things even easier for very large files with hundreds of entries.

Enjoy power coding!


One thought on “Wrestling with large code amounts and winning: multi-line editing

Leave a Reply

Your email address will not be published.