christopher keene
christopher keene

Reputation: 13

I don't understand the format selection (cmd + K cmd + F) shortcut keys in VS Code

Can someone please explain to me how the "format selection" (cmd + K cmd + F) shortcut keys - and other shortcuts that seemingly have multiple button press combinations - work in VS Code.

I tried pressing cmd + K and cmd + F simultaneously (though, cmd is listed twice so I am really pressing cmd + K + F in this case) and I have tried hitting them in order. If someone could explain what they mean here, then it would be much appreciated. I am sure it's a simple solution that I have been overlooking for all these years.

Upvotes: 0

Views: 1215

Answers (1)

Stelio Kontos
Stelio Kontos

Reputation: 510

The written format for shortcut expressions use the operators '+' (plus) and ' ' (space) to define whether the expressions on each side of the operator should be pressed simultaneously, or sequentially.

  • '+' represents two keys pressed then held simultaneously, in left-to-right order.

    This is the same as typing an uppercase letter using the shift key: Shift+a -> A

  • ' ' represents concatenating the right-hand-side key combo after the left-hand-side combo.

    This is the same as typing an uppercase word using the Shift key: Shift+h Shift+i -> HI

In the second example above, note that you can either keep holding Shift, or you can release it and press it again for each letter. The same applies with VSCode shortcuts.

In the case of Format Selection (Cmd+k Cmd+f), Cmd should be held while first k then f are pressed. Pressing k and f together is a different shortcut entirely (Cmd+k+f), as is pressing f and k together (Cmd+f+k). Since the left-hand-side key (Cmd) is the same for both expressions, you don't need to release it between typing the k and f.

To get a better grasp of how keyboard shortcuts are expressed, I'd suggest opening the the VSCode Preferences for Keyboard Shortcuts either using the command palette, or using the shortcut: Cmd+k Cmd+s: (type ks while holding Cmd).

Then activate the Record Keys mode (Alt+K). Now type different key sequences, and it will show you the textual representation in the search bar, along with any shortcuts that match what you typed.

enter image description here

Upvotes: 1

Related Questions