VS Code Shortcuts to Deploy LWC, Apex, Triggers & Everything

Shortcuts to deploy Salesforce metadata in VS Code

Tip: Edit your keybindings.json file with JSON code given below and your shortcuts will be ready. 

Steps to Open keybindings.json:

  1. Open VS Code
  2. Press Ctrl + Shift + P
  3. Open Keyboard Shortcuts (JSON) / keybindings.json
  4. Replace the file with following JSON code
[
  {
    "key": "ctrl+d",
    // "command": "sfdx.force.source.deploy.source.path"
    // replace sf with sfdx if you have latest sfdx version
    "command": "sf.deploy.current.source.file"
  },
  {
    "key": "alt+s alt+o",
    "command": "sfdx.force.org.open"
  },
  {
    "key": "alt+r",
    "command": "sfdx.force.source.retrieve.source.path"
  },
  {
    "key": "alt+s alt+t",
    "command": "sfdx.force.apex.test.last.method.run"
  },
  {
    "key": "alt+s alt+r",
    "command": "sfdx.force.source.retrieve.in.manifest"
  },
  {
    "key": "alt+s alt+.",
    "command": "sfdx.force.source.deploy.in.manifest"
  }
]

What shortcuts we have added:

  • ctrl+d: Deploy any type of salesforce components 
  • alt+s alt+o: Open org
  • alt + r: Retrieve current open file mdt
  • alt+s alt+r: Retrieve in manifest
  • alt+s alt+.: Deploy files added in manifest

Note: If you are using latest version of sfdx then replace all sfdx with sf. 

sfdx is being deprecated, sf is the replacement.

Our recent posts

How to use these shortcuts

  1. Open the Command Palette with Ctrl+Shift+P and run Preferences: Open Keyboard Shortcuts (JSON).
  2. Paste the entries from above into the array. Keep a comma between entries.
  3. Save the file. The shortcuts work at once.

Points to note

  • Ctrl+D already has a job. In VS Code it selects the next match of the current word. If you use that, pick another key for deploy, for example ctrl+alt+d.
  • The commands changed. Newer versions of the Salesforce Extension Pack use command ids that start with sf. instead of sfdx.force.. If a shortcut does nothing, the command id may be old.
  • To find the right id, open Preferences: Open Keyboard Shortcuts, search for the command name such as SFDX: Deploy This Source to Org, click the plus icon and set the key there. Then open the JSON view to copy the id.
  • The shortcuts act on the file that is open in the editor.

FAQ

Do I need the Salesforce Extension Pack?
Yes. The commands come from the Salesforce extensions in VS Code.

Can I add a when condition?
Yes. Add "when": "editorTextFocus" to an entry if the shortcut should work only while you type in the editor.

Leave a Reply