Mastering Powerful Features in VSCode: Tips and Tricks
vscode has become a go-to for a lot of devs but its surprising how many people simply use it simply as an IDE, while ignoring its many powerful features. it can be especially powerful when doing tedious text modifications in JSON files or otherwise.
select same text in file
windows - CTRL + D
macOS - CMD + D
say you have the same class applied to mutilple divs but you would like to change its name for the first three instances, you simply press the command above and repeat it for each selection, then type in as you normally would.
select all instances of text in file
windows - CTRL + L
macOS - CMD + Shift + L
say you want to select all instances of some text in file, you select your text then press the command above, giving you a cursor against all instances of that text in your file.
add cursor at click
windows - CTRL + click
macOS - CMD + click
you can also manually add mutiple cursors by using the command above, giving you finer control over cursor placement.
duplicate selection
windows - SHIFT + ALT + Down
macOS - SHIFT + OPT + Down
to quickly duplicate lines, select your text then press the command above.
remove duplicates
suppose you are working with a list of restaurants, but there are duplicated entries.
to get a list of all unique values, do the following
CMD + P or CTRL + P
Type > Sort
Select Sort Lines Ascending
then do the following (source)
Control + F.
Toggle “Replace mode”
Toggle “Use Regular Expression” (the icon with the .* symbol)
In the search field, type ^(.*)(\n\1)+$
In the “replace with” field, type $1.
Click. (“Replace All”).
and what you end up is with all the unique values