Many text editors have a feature where if you select text with the Alt key pressed, multiple columns will be selected.
This is different from simply making a selection that starts and stops on different lines. Instead, each line will have a selection region that starts and stops on the same column. This allows for surgical accuracy when selecting across the multiple rows of text.
Programs such as Visual Studio, MonoDevelop, Notepad++, etc; many text editors and IDEs will support this, so if there’s a main text editor you use, try it out and see if your editor of choice supports it.
Simple editors like Notepad or browser text fields will not support this.
Visual Studio Code uses Shift + Alt with mouse selections. (It’s frustrating)
Example
In the example below, I’m taking a list of operator names and constructing unit tests for them. Instead of preparing each tests’ declaration individually, I use Alt+select to change each line in lockstep.
In the video, I forgot to make the functions public. This was later easily fixed by doing a Find and Replace All with the term void
and replacing it with public void
.
While a script could have been written to automate this kind of work, it’s not sensible to make automation scripts for one-off tasks. So while the editing is done manually, it’s also done in batch with the Alt key.
There’s little touch-up work that needs to be done here-and-there, but for the most part, it’s sane and doesn’t involve much manual labor. Not only that, if the text copied over were 10x longer, this example would have still been the same amount of work.
Different Behaviours
Not all text editors that support Alt selection will behave the same. While the boxed selection may visually look the same, I’ve noticed the editors will do different things for some operations. This is especially true for copy and paste. This difference in behavior gets more intense when considering what an application does if Alt selected text in the clipboard is pasted into an Alt selection region.
– Stay strong, code on. William Leu