Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCODE snippets : Force intellisense after only one character pressed

I'm new to VSCode and I want to test it to compare with my sublime text configuration. I want to create a very simple snippet that allow me to write ruby code <%= %> when I only press < key.

Here is my snippet's code :

    "My snippet": {
        "prefix": "<",
        "body": [
            "<%= $1 %>"
        ],
        "description": "My snippet"
    }

So this code works but I have to press Ctrl+Space in my file to show the IntelliSense list (with my snippet). I just want to press < and Tab to complete this, not to press Ctrl+Space always.

Do you know if there's a configuration to do it ?

Thanx

like image 718
John Avatar asked Dec 08 '16 09:12

John


People also ask

How do you trigger snippets in VS Code?

To create or edit your own snippets, select User Snippets under File > Preferences (Code > Preferences on macOS), and then select the language (by language identifier) for which the snippets should appear, or the New Global Snippets file option if they should appear for all languages.

How does VS Code trigger IntelliSense?

You can trigger IntelliSense in any editor window by typing Ctrl+Space or by typing a trigger character (such as the dot character (.)

What is IntelliSense in VS Code?

IntelliSense features. VS Code IntelliSense features are powered by a language service. A language service provides intelligent code completions based on language semantics and an analysis of your source code. If a language service knows possible completions, the IntelliSense suggestions will pop up as you type.

What are snippets in Visual Studio Code?

Snippets in Visual Studio Code Code snippets are templates that make it easier to enter repeating code patterns, such as loops or conditional-statements. In Visual Studio Code, snippets appear in IntelliSense (Ctrl+Space) mixed with other suggestions, as well as in a dedicated snippet picker (Insert Snippet in the Command Palette).

What is a Level 1 snippet in IntelliSense?

This snippet inserts a level 1 heading which wraps the markdown around the current selection (if there is one). "Insert heading level 1" is the snippet name. This is the value that is displayed in the IntelliSense suggestion list if no description is provided. The prefix property defines the trigger phrase for the snippet.

Can I hide specific snippets from showing in IntelliSense (completion list)?

# Yes, you can hide specific snippets from showing in IntelliSense (completion list) by selecting the Hide from IntelliSense button to the right of snippet items in the Insert Snippet command dropdown. You can still select the snippet with the Insert Snippet command but the hidden snippet won't be displayed in IntelliSense.


2 Answers

It is a long time since your question, but I think it may help others.

In settings you need to enable editor.tabCompletion, then you can press tab even if there is no IntelliSense.

like image 140
Aron Avatar answered Oct 19 '22 06:10

Aron


To have the snippet auto-injected into the VS Code Editor when you press Tab after the prefix (even this is only one character), you need to set the editor.tabCompletion setting to onlySnippets, neither off nor on.

    "editor.tabCompletion": "onlySnippets",

personally, I think this is a very strange behavior, and that, in theory, with the value on the tabCompletion option should also work. but somehow this option works like that, at least for me.

like image 33
almaceleste Avatar answered Oct 19 '22 07:10

almaceleste