![]() This post is part of the series 'Visual Studio Tips and Tricks'. You can select just the next matching location by using Alt+Shift+. Visual Studio will select all the locations that match the selected text in the current document. Select the word you want to match and press Alt+Shift+. Right now in order to perform a multi-cursor edit in SublimeText3 I press Ctrl and click the places I want to edit. You can insert a caret at all places where the current word exists. Press Ctrl+Alt and click where you want to add a caret. If you want to edit multiple places that are unaligned, you can use the multi-cursor edit. Thats why I was asking for something similar for multi-cursor selection. To place cursors next to all instances of a highlighted word. When the cursor is on the variable you want to rename, click F2 you will see a prompt like this. Selects the word under the cursor or the current selection's next occurrence. ![]() Press Alt+Shift+Arrow to select the block to edit: It will rename only, but all the variable instances in the file. Press Alt while selecting the block with the mouse: For instance when you want to add the modifier to multiple properties. This is very useful to apply the same change to multiple lines. I made this easier by using “export” as an anchor, but you can do more complex finds by using regular expressions.Visual Studio allows to edit multiple lines at the same time. Select interface/class names ( Ctrl+Shift+Left).Move cursors after interface/class names ( Ctrl+Right, 2 times).Select all of the find matches ( Ctrl+Shift+L).Each cursor operates independently based on the context it sits in. You can add secondary cursors (rendered thinner) with Alt+Click. Find all occurrences of “export” ( Ctrl+F, type “export”, Esc) VS Code supports multiple cursors for fast simultaneous edits.How can we select and copy the names of every interface and class? Fortunately, we can use good old “Find” to select all the areas we’re interested in and drop cursors on them.įor example, consider a file with several interfaces and classes. They could be in different parts of the file. The lines we’re interested in won’t always be on top of one another. Notice how after step 2, the cursors are vertically offset, but they’re all in the same position relative to the variables. Move to right of variable name ( Right, 2 times).Insert cursors on lines below ( Ctrl+Alt+Down, 4 times).Instead, let’s take advantage of other navigation shortcuts. What if we need them offset? We could use Alt+Click to place each cursor individually, but that would take a while if you had lots of lines. It was easy to place cursors using Ctrl+Alt+Up because we needed cursors at the same position on each line (i.e. You can imagine how much this would speed things up if you had a longer list. Bring all names into one line ( Backspace).Insert cursors on lines 4, 3, and 2 ( Ctrl+Alt+Up, 3 times).Move to beginning of last line ( Ctrl+Left).You could manually bring them into one line and add commas between. (Bonus points if you know why I chose those names.) And you wanted to put them into a comma-separated string. Say you copied a list of names from somewhere: To illustrate, here are a few cases I’ve come across where I’ve used multiple cursors extensively. Shift+: Select from previous position to new position.Of course, your lines won’t always align so nicely, so you may have to use a clever combination of other navigation shortcuts to achieve your goal. Once you have your cursors in place, you can type as usual and your changes will apply to each cursor location. Ctrl+Alt+Up: Add a new cursor above your current one.Ctrl+Alt+Up: Add a new cursor above your current one. Ctrl+Alt+Down: Add a new cursor below your current one. ![]() Here are the important shortcuts in Visual Studio Code (on Windows): Alt+Click: Place a new cursor where you click. Ctrl+Alt+Down: Add a new cursor below your current one Visual Studio Code is my go-to editor nowadays, and it comes with multiple cursor support out of the box.Alt+Click: Place a new cursor where you click. ![]() Here are the important shortcuts in Visual Studio Code (on Windows): Visual Studio Code is my go-to editor nowadays, and it comes with multiple cursor support out of the box. It sounds like more trouble than it’s worth, but once you learn the shortcuts, it becomes natural. Multiple cursors is exactly what it sounds like: it lets you place more than one cursor in your editor so you can edit multiple locations at the same time. ![]() Now I use it every day, and I keep finding new ways to speed up otherwise tedious tasks. I had seen it before when digging through editor settings, but I had never bothered to actually try it until recently. Programming using multiple cursors had always been a mystery to me. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |