Every meow and then on the /r/learnprogramming sub I get an opportunity to tell someone about some neat feature or shortcut on VSCode that just blows their mind and makes me look like a super-ninja. I thought I'd collect a few of those tips together here for anyone looking to improve their day-to-day efficiency, without actually having to learn anything.
I'm not going to get into workflows or workspaces or workstations. I'm not even going to talk about source control (although I most certainly will in a later article).
Nope, these are just a few little tricks I use pretty much every day, mostly without even thinking about it. And although VSCode has been my daily driver for a few years, most of these are actually pretty universal so it'll be worth checking if they work anyway in your own IDE - for instance the move line function exists in Notepad++, it's just CTRL + SHIFT + ↑ / ↓
instead of ALT + ↑ / ↓
.
Source: KlingAI
Tip[05] = Move Line Up/Down with ALT + ↑ / ↓
Whether it's re-ordering imports or refactoring functions, you're going to need to move lines of code around. Using this trick makes things a snap; instead of selecting a line and cutting it, then pasting it in the new spot, I can just use the Move Line functionality to relocate it quicker than thought.
In this example, I want to re-order the items in my list of sets so they appear in chronological order. I just position the cursor anywhere on the line I want to move, and tap ALT + Down Arrow
a couple times and move it to the new position. So what would take a couple few minutes the 'old' way takes a few seconds meow.
Source: VSCode on Linux Mint, captured using Peek (Applies to all code images here)
It also works with multiple lines:
The only real issue with this one is you'll get so used to it that you'll try to use it in every interface.*
*This sentence was meant to be above the image, but I ain't manually moving it there after being spoiled by my IDE.
Tip[04] = Multi-Cursor with CTRL + D
This little guy is a total game changer. You’ve got the same word or variable all over the place, and you want to change it. Instead of fixing each instance one by one, you select a single one then hit CTRL + D
. It'll highlight the next matching instance; you keep tapping and voila you’ve got multiple cursors, all ready to be edited simultaneously.
It’s like being in five places at once, really cool places, with lots of free food and naked ladies/dudes.
By default, it has the word highlighted, but if you press the arrow key to either left or right you can go to either end of the selection instead. For instance to change all instances of "mana" to "card.mana" you would select "mana", cycle through with CTRL + D
, and then hit left arrow then type "card." - I think you can see how handy this guy is.
I tend to use this more than the regular Find, even if I don't need the multi-cursor since it's just muscle memory at this point.
Tip[03] = Copy Line with CTRL + SHIFT + ALT + ↑ / ↓
This one is fantastic for when you need to lay out a bunch of similar lines. Just drop your cursor anywhere in the line and smash CTRL + SHIFT + ALT + ↑ / ↓
a bunch times. Duplicates of your line will appear above or below, ready to edit.
It also works on multi-line selections if you want to copy whole Functions or Interfaces or Components or anything else you can dream of.
Tip[02] = Magic Cut: CTRL + X
anywhere in line.
This one is brilliant, it's also another one that I accidentally try and use everywhere all the time. I guess I just really don't like selecting things.
The basic gist of this is that you can use the regular Cut function to wipe out a line from anywhere in it. Super useful for things like deleting commented out code that you've duplicated to modify, among a plethora of other obvious uses. And of course if you do a lot of text navigation through your code, this is wicked handy since you can avoid the mouse entirely.
Tip[01] = Comment out Lines or Chunks with CTRL + /
This one is in every IDE in some form, but in VS Code it's CTRL + /
by default. I use this pretty much every day, and it's especially handy when you're bouncing between different file types.
Whether it's !--
or /* */
or #
or //
or something else, as long as VSCode recognizes the filetype, it will supply the appropriate commenting syntax and wrap your line or chunk in it.
I guess I still occasionally type //
in front of a line, but I honestly can't remember the last time I manually wrote opening AND closing tags for a comment, in any IDE.
Tip[00] = Click This in the Welcome Screen:
I avoided this for so long, because 'too busy, gotta do a thing! ' but when I finally did I was blown away by how much stuff is in there, and how quickly it moves through it. It's got mini-video demos of most of these features; this is where I learned about Multi-Cursor the first time (and there's lots more Multi-Cursor functionality in there, we've only scratched the surface).
Snack Overflow
You can write your code however you want. But if you're going to be in VSCode all day, every day, you might as well let it do some of the heavy lifting. These little tricks alone have probably saved me exactly 200 days of clicking and dragging and cutting and pasting and finding and replacing.
And if you’re already using them right meow? Awesome. You’re living in the future.
Source: KlingAI
Nice, super useful. I didn't know any of these!
!PIZZA
i basically mark my life by pre- and post- knowing about multi cursor hahaha
When I need mass replace I hit Ctrl + H
Not sure how that compares to Ctrl + D exactly, for the purpose of just changing a variable name everywhere.
ummm.... the best way i can describe it is it just FEELS different. just crack a piece of code and select something and hit CTL D. since you somewhat manually select each instance, you know 100% what will be changed. plus, no dialog box, you're not entering a serach, entering a replacement, then hitting go.... you're multi selecting and multi editing.
i only ever use CTL H if i want to find and replace across multiple files these days.
to expand on my last answer a little, it just a whole new paradigm.... i get it, i've used CTL - H for YEARS. but being able to select.... like lets say you have a file with dozens of instances of 'card' and you want to replace certain early functions that include card with player.card. you don't want every instance of card, that would break your program -- so you double click the first iteration of card (select word) and then hit control D to grab the others you want to modify. if you went one too far? ctl - U unselects that one. so you double click a name, hit CTL D however many times, and then type the new name. like i say, game changer. it's sooooo different than ctl-f ctl-h, its more pinpoint, and so much smarter
The rewards earned on this comment will go directly to the people( @coderad ) sharing the post on Reddit as long as they are registered with @poshtoken. Sign up at https://hiveposh.com. Otherwise, rewards go to the author of the blog post.
$PIZZA slices delivered:
@agrante(1/5) tipped @coderad
Come get MOONed!
Congratulations @coderad! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)
Your next target is to reach 3250 upvotes.
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP