0

How can I change snippet trigger key to Ctrl+k? I tried these settings (from default keybindings file):

{ "key": "ctrl+k", "command": "insertSnippet", "when": "config.editor.tabCompletion && editorTextFocus && hasSnippetCompletions && !editorTabMovesFocus && !inSnippetMode" } but it doesn't work as expected, i.e. nothing happens.

I want to have this workflow:

  1. type log in javascript file and hit Ctrl+k.
  2. vscode looks for a log snippet and if it exist then expand snippet.
  3. type something at current tabstop, hit Ctrl+k to go to another tabstop point.

For the last step there are jumpToNextSnippetPlaceholder command. But I'm stuck with initial action on first step. Can anyone help?

Cheers!

1 Answer 1

1

So, I investigated some time in reading documentation and ended up with following preferences (keybindings.json):

{
    "key": "ctrl+k",
    "command": "insertSnippet"
},
{
    "key": "ctrl+k",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus && editorHasSelection"
},
{
    "key": "ctrl+k",
    "command": "jumpToNextSnippetPlaceholder",
    "when": "editorTextFocus && inSnippetMode"
},
{
    "key": "shift+ctrl+k",
    "command": "jumpToPrevSnippetPlaceholder",
    "when": "editorTextFocus && inSnippetMode"
}

Maybe it could help anyone.

Sign up to request clarification or add additional context in comments.

1 Comment

There is another way to quickly trigger snippets. You can add this preference to you user setting file: "editor.snippetSuggestions": "top". After that all snippets will be display on the top of a suggestion popup, so you only need to hit Enter\Tab key to select correct snippet. Horray!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.