Skip to content

Commit

Permalink
feat: adjust shift+cmd+k to clear terminal by default
Browse files Browse the repository at this point in the history
  • Loading branch information
tjx666 committed Sep 9, 2024
1 parent 92278d8 commit 7bef3dc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Key improvements:
- `⇧ + ⌘ + K`: Restored as "Delete Line" (previously "Open Edit" in Cursor, now `⌘ + E`)
- `⌘ + L`: Restored as "Expand Line Selection" (previously "Open New Chat" in Cursor, now `⌘ + ]`)
- `⇧ + ⌘ + L`: Restored as "Select All Occurrences of Find Match" (previously "Insert Selection Into Chat" in Cursor, now `⌘ + ⇧ + ]`)
- `⇧ + ⌘ + K`: Clear terminal output instead of `⌘ + K` [#3](https://github.com/tjx666/vscode-classic-experience/issues/3)

This extension will not modify any of your Cursor settings or local application files. It simply removes certain Cursor shortcuts and restores the original VSCode shortcuts using the extension API. There's no hidden magic involved. If you ever wish to revert to Cursor's original shortcuts, you can easily do so by disabling or uninstalling this extension.

Expand All @@ -34,10 +35,16 @@ this bring back the original vscode activity bar and side bar layout, just like

```jsonc
{
// don't forget to restart to take effect
"workbench.activityBar.orientation": "vertical",
}
```

How to custom vscode keybinding?

- [Key Bindings for Visual Studio Code](https://code.visualstudio.com/docs/getstarted/keybindings)
- [Customize Visual Studio Code Video Tutorial](https://code.visualstudio.com/docs/introvideos/customize)

## Alternatives

While you can restore the `⌘ + K` keybinding prefix by changing the `workbench.action.keychord.leader` to `⌘ + K`, this approach has some drawbacks:
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,11 @@
"command": "views.moveViewUp",
"when": "focusedView != ''"
},
{
"key": "cmd+k",
"command": "-workbench.action.terminal.clear",
"when": "terminalFocus && terminalHasBeenCreated && !accessibilityModeEnabled || terminalFocus && terminalProcessSupported && !accessibilityModeEnabled || accessibilityModeEnabled && accessibleViewIsShown && terminalHasBeenCreated && accessibleViewCurrentProviderId == 'terminal' || accessibilityModeEnabled && accessibleViewIsShown && terminalProcessSupported && accessibleViewCurrentProviderId == 'terminal'"
},
{
"key": "cmd+k",
"command": "-composer.startComposerPrompt",
Expand Down Expand Up @@ -1023,6 +1028,11 @@
"command": "expandLineSelection",
"when": "textInputFocus"
},
{
"key": "shift+cmd+k",
"command": "workbench.action.terminal.clear",
"when": "terminalFocus && terminalHasBeenCreated && !accessibilityModeEnabled || terminalFocus && terminalProcessSupported && !accessibilityModeEnabled || accessibilityModeEnabled && accessibleViewIsShown && terminalHasBeenCreated && accessibleViewCurrentProviderId == 'terminal' || accessibilityModeEnabled && accessibleViewIsShown && terminalProcessSupported && accessibleViewCurrentProviderId == 'terminal'"
},
{
"key": "cmd+r",
"command": "-workbench.action.keychord.leader",
Expand Down
24 changes: 16 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function generateKeybindings(extensionPath: string) {

// cmd + k used as shortcut prefix, remove all 'cmd+k' shortcuts
const removedCmdKKeybindings = keybindings
.filter((kb) => kb.key === 'cmd+k' && !kb.command.startsWith('workbench.'))
.filter((kb) => kb.key === 'cmd+k')
.map((kb) => {
return {
...kb,
Expand All @@ -44,13 +44,15 @@ async function generateKeybindings(extensionPath: string) {
});

// replace `cmd+k` to `cmd+e`
const cmdEKeybindings = removedCmdKKeybindings.map((kb) => {
return {
...kb,
key: kb.key.replace('cmd+k', 'cmd+e'),
command: kb.command.slice(1),
};
});
const cmdEKeybindings = removedCmdKKeybindings
.filter((kb) => !kb.command.startsWith('-workbench.'))
.map((kb) => {
return {
...kb,
key: kb.key.replace('cmd+k', 'cmd+e'),
command: kb.command.slice(1),
};
});

// extra often used shortcuts in vscode to remove
const shortcutsToRemoved: Keybinding[] = [
Expand Down Expand Up @@ -85,6 +87,12 @@ async function generateKeybindings(extensionPath: string) {
command: 'expandLineSelection',
when: 'textInputFocus',
},

// clear terminal
{
...keybindings.find((kb) => kb.command === 'workbench.action.terminal.clear'),
key: 'shift+cmd+k',
},
];

const keyChordLeader = [
Expand Down

0 comments on commit 7bef3dc

Please sign in to comment.