Keyboard shortcut to revert selected local changes in Cursor

WebStorm shortcuts deeply rooted in muscle memory are hard to ignore when using other IDE’s. A frequent flyer for me is the shortcut to ‘rollback’ lines in WebStorm with cmd+opt+z.

In Cursor there is no such shortcut defined by default so you have to remove changes manually or click in the margin to open the local changes view then click the Revert Change button. That feels like too much work when already used to a shortcut for this.

Adding a new keybinding

To add the same shortcut in Cursor we need to know which command to trigger. In this case it is git.revertSelectedRanges. Open keyboard shortcuts and search for git.revertSelectedRanges. There may already be a keybinding assigned to it but I want to change that. Right click on the entry and select Change Keybinding.... In the resulting prompt, type cmd+opt+z and press Enter. Now the new keybinding is mapped and will revert local changes when used.

User keybindings

Note that the changes made in the UI are written to a user keybindings file. For reference the file is located in /Users/<user>/Library/Application Support/Cursor/User/keybindings.json on mac.

You can view it within the IDE via the command palette; search for keyboard and select: Keyboard Shortcuts: Open Keyboard Shortcuts (JSON).

Here we see our new keybinding and the keybinding that we replaced. The replaced one is denoted by the - in front of the command.

  {
    "key": "alt+cmd+z",
    "command": "git.revertSelectedRanges",
    "when": "editorTextFocus && !operationInProgress && resourceScheme == 'file'"
  },
  {
    "key": "cmd+k cmd+r",
    "command": "-git.revertSelectedRanges", 
    "when": "editorTextFocus && !operationInProgress && resourceScheme == 'file'"
  }