Visual Studio Code Select Column Mac
In this step, we explore some of the more advanced features of Visual Studio code, such as how to use the integrated terminal and our newly installed Salesforce Extension Pack.
Sep 13, 2019 Mac: Shift + Cmd + L Select a word and press Shift + Cmd + L to select all instances of your selection. Shift + Alt/Option + I Select a bunch of lines, then Shift + Alt/Option + I will put a cursor at the end of every selected line. Visual Studio is a fully-featured IDE whereas Visual Studio Code is a code editor. Visual Studio Code is free and based on open source, and runs on Windows, macOS, and Linux. Check out this doc for a more detailed understanding of the differences. The user setting Editor: Column Selection controls this feature. Once this mode is entered, as indicated in the Status bar, the mouse gestures and the arrow keys will create a column selection by default. This global toggle is also accessible via the Selection Column Selection Mode menu item.
Like with any good development tool, there is more than one way to do things with Visual Studio Code. The two main ways you can interact with Salesforce CLI are through the integrated terminal or quick open window.
To view the quick open window, press Command + P on Mac or Ctrl + P on Windows. If you type ?
you can view the help menu. Through this module we will use the quick open window in command palette mode, which allows us to show and run commands.
Create a Project
- Press Command + Shift + P on Mac or Ctrl + Shift + P on Windows to make the command palette appear.
- Make sure the new prompt starts with
>
- Type SFDX: Create Project and press Enter to select the standard template.
- Type the project name
VSCodeQuickstart
and press Enter. - Select your Desktop as the place to create the project in so it is easy to find later on.
- Wait for the new Visual Studio Code window to open. You should see an indication that the extension is preparing your project before populating the file explorer.
- Press Command + P on Mac or Ctrl + P on Windows to make the search palette appear. This shifts the focus to search files.
- Type
project-scratch-def.json
into the field. - Click the result to open the file.
- On the left hand side of Visual Studio code, click the Find and Replace menu.
- Search for
orgName
. - In the first result found in project-scratch-def.json.
- Change the orgName value (after the : and in between the “”) to
Learning VS Code
. - Save the file by pressing Command + S on Mac, Control + S on Windows.
Authenticate to Your Playground
Visual Studio Code Select Column Mac Version
- Press Command + Shift + P on Mac or Ctrl + Shift + P on Windows to make the command palette appear.
- Type
SFDX: Authorize an Org
. - To accept the default login URL, press Enter.
- Enter the alias
VSCodePlayground
. - Notice that your default browser opens a new Salesforce login window. Log in to your playground using your playground username and password retrieved from the last step.
- When you are asked to grant access to the connected app, click to allow.
- Close the browser window.
The command-line terminal window returns a success message when the transaction is complete.
- Click the Explorer icon in Visual Studio Code to expand the force-app folder.
- Under the VSCODEQUICKSTART directory, click force-app to show its folder tree. In the force-app/main/default directory, you find the metadata included within the project such as applications, aura, classes, and more.
- Press Command + Shift + P on Mac or Ctrl + Shift + P on Windows to make the command palette appear.
- Type
SFDX: Create Apex Class
. - Enter the name
AccountController
. - If VS Code asks, select force-app/main/default/classes as the directory you wish to add
AccountController.cls
to. - In the newly opened AccountController.cls file, replace the default code with the following:
- Save your file.
Query
Our new Apex class has a SOQL query in it, but we want to make sure it works as we expect before we deploy it to our org. We use the command palette to run the query against our org.
- In line 3 of the code, highlight the query
SELECT Id,Name,Active__c FROM Account WHERE Active__c = 'Yes'
- Press Command + Shift + P on Mac or Ctrl + Shift + P on Windows to make the command palette appear.
- Search for
SFDX:Execute SOQL Query with Currently Selected Text
. - Press Enter.
- Select REST API and press Enter.
- In the Output tab of the integrated terminal window, review the results of your query. The window should state a summary that says: SFDX: Execute SOQL Query ... ended with exit code 0. This means it successfully ran.
The last step is to deploy your code to your playground from within Visual Studio Code.
- Right click the classes folder.
- Click SFDX: Deploy Source to Org.
- In the Output tab of the integrated terminal, view the results of your deployment. You should have also received a notice that states: SFDX: Deploy Source to Org ... ended with exit code 0. This means it successfully ran.
Parting Thoughts
You’ve learned how to use Visual Studio Code and the Salesforce Extensions. You’ve seen how the features of an IDE can help maximize your development efficiency. Now you’re ready to explore some of the more complex topics, such as debugging with the Apex Replay Debugger, customizing your editor to fit your needs, and running your developer pipelines with Visual Studio Code.
Last week I learnt a really clever little trick in Visual Studio from Marthin Freij. While it’s a very old feature in Visual Studio it was news to me that you could select columns of text. That is, if you hold down SHIFT + ALT while dragging the mouse pointer over a block of text you wont select the entire rows of text that you have dragged the mouse pointer over but only the text in the area that you dragged over. That is, without holding down SHIFT + ALT you could end up with a selection like this:
If you instead hold down SHIFT + ALT while dragging the mouse pointer your selection would instead look like this:
Visual Studio Code Select Column Machine
Know of another really cool and elegant but not so well known feature in Visual Studio? Please enlighten me in a comment!
PS. For updates about new posts, sites I find useful and the occasional rant you can follow me on Twitter. You are also most welcome to subscribe to the RSS-feed.