简体   繁体   中英

Add a shortcut key in VSCode that is active when the “Git: Open Changes” editor is active

I'm using the "Git: Open Changes" command to see my git stages, and inside that editor I use the "Git: Stage selected ranges" command to stage changes. I would like to automate the latter command using a short-cut key. What should I put in the "When" field of the VSCode shortcuts page so that the shortcut is only active in the editor that shows me the open git changes?

More generally, what is the correct way to identify a specific editor in the "When" column? (what are the steps to be able to reference any editor there)

You can assign a shortcut to the command id:

git.stageSelectedRanges [Default: CTRL + K chord CTRL + ALT + S ].

But to answer how to apply shortcuts to only when the diff editor is active you can use the following keybind context in your when expression:

isInDiffEditor

In combination to whatever else you wish, of course. This, at minimum, will only apply when the diff editor is active.

You can review other contexts per their documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM