Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Keybinding EvalNew to Visual Studio Code? Get it now.

Keybinding Eval

LiangSai

|
305 installs
| (2) | Free
Keybinding Eval
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

README

This is the README for "Keybinding Eval".

Features

Eval Script Code Command In Your keybindings.json

It's more powerful and simple than macro and multi-command.

It can eval multiple custom script line in keybindings.json.

Example

Edit your User Keybindings.json

    {
        "key": "ctrl+shift+t",
        "command": "extension.keyboard_shortcut_eval",
        "args": {"javascript": "vscode.window.showInformationMessage('100'); vscode.commands.executeCommand('workbench.action.terminal.toggleTerminal');"}
    }

Press CTRL + SHIFT + T, it do two work by javascript eval function.

vscode.window.showInformationMessage('100');
vscode.commands.executeCommand('workbench.action.terminal.toggleTerminal');

Initial release.

Enjoy!

How to recreate same extension?

https://code.visualstudio.com/api/get-started/your-first-extension

npm install -g yo generator-code
cd your workdir
yo code  
----(identifier all lowercase, typescript type)
cd project-dir
code .

extesion.ts

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {

	let disposable = vscode.commands.registerCommand('extension.keyboard_shortcut_eval', (args) => {
        if(args && args.javascript && typeof args.javascript == "string")
        {
            eval(args.javascript);
        }
        else{
            let str = `(Pleas copy this message text) Extension.keyboard_shortcut_eval command need set keyboard shortcut command args, args object key=javascript, keybindings.json example:
"command": "extension.keyboard_shortcut_eval",
"args": {"javascript": "vscode.window.showInformationMessage('100'); vscode.commands.executeCommand('workbench.action.terminal.toggleTerminal');"}`;
            vscode.window.showInformationMessage(str);
        }
	});

	context.subscriptions.push(disposable);
}

export function deactivate() {}

ctrl+shift+b npm watch && F5 test

Publish your extension

https://code.visualstudio.com/api/working-with-extensions/publishing-extension

My first extension, about 4 hours worktime.

You can recreate this extension in 1 hour. See above.

  • Contact us
  • Jobs
  • Privacy
  • Terms of use
  • Trademarks
© 2023 Microsoft