
Press Esc to cancel the multiple selections. Or you can use the navigation keys to move all your multi-cursors. Keep typing ⌘D to select the next occurrence, and so on.įinally, when you’ve selected all the occurrences of the text that you want to change, just type, and your typing will replace all the selections. You’ll see that the next occurrence of the selected text in the file is also highlighted, and has a multi-cursor. Type Esc to go back to single-cursor mode. Keep pressing ⌥⌘↓ to insert more multi-cursors on successive lines.Įverything you can do with the single cursor, such as editing commands, you can do in many places at once with multi-cursors. This will add a multi-cursor on the next line at the current cursor position. To add multi-cursors without using the mouse, press ⌥⌘↓.

Each ⌥-drag adds a new selection, and when you type, it will replace all your selections. Each click will insert a new multi-cursor.įor example, to add a trailing comma to each line of a struct literal, ⌥-click at the end of each line and then type a single comma.Īlternatively, you can hold ⌥ and drag the mouse to select a chunk of code. Hold down the ⌥ key, position the mouse pointer where you want it, and click the left mouse button. Then just type, and your new text will be inserted at each of those cursors. When you need to perform the same editing operation on several lines at once, you can ⌥-click to insert a new cursor everywhere you need it. Multi-cursors are one of the neatest features of VS Code. If you need to temporarily enable or disable a block of lines, select them and type ⌘/ to comment them all out. When you do, though, ⌘] and ⌘[ will move the current line or selection one indent stop right or left. Indent / outdent lineīecause VS Code will auto-format the current file every time you save it, you don’t need to manually indent and outdent lines very often. You don’t have to select the whole line, or lines, and then cut: ⇧⌘K deletes the line the cursor is on immediately, or selected lines if there’s a selection. Similarly, ⇧⌘Enter inserts a new line above. When the cursor is in the middle of a line, you don’t have to jump to the end before inserting a new line below: just type ⌘Enter instead.


Instead of selecting lines, cutting, clicking to reposition the cursor, and pasting, you can move the current line or selected lines directly. These are the default shortcuts on macOS on Windows, use Ctrl instead of ⌘, and Alt instead of ⌥. Here are some of the most useful keyboard shortcuts to know when editing Go code. The symbols on your keyboard may be slightly different, but you’ll figure it out. VS Code uses various modifier keys, and I’ll refer to them using the (Mac-specific) symbols that VS Code itself uses in its documentation:

Instead, learn yourself some keyboard superpowers, for great justice. Sure, you can do everything by pointing and clicking with the mouse, but that’s slow, and experienced programmers tend to avoid unnecessary mousing. The first thing to master in VS Code is the basics of typing text, editing it, and moving it around. Let’s cape up and take a tour of the seven superpowers of VS Code for Gophers. With the Go extension installed, it’s the perfect accessory for a Go superhero. Visual Studio Code is the most popular Go editor, and no wonder: it’s the Batman’s utility belt of editors. But assuming you have those, a few well-chosen tools can really help you a lot. All you need is intelligence, dedication, and a keen sense of justice. Not all superheroes wear capes, and you don’t need any fancy accessories to be one, either. JOKER: Where does he get those wonderful toys?
