'Auto completion in VS Code

I find that in vs code I can start to type console.log I can leverage intellisense to auto complete the console.log and the cursor is inside the parentheses. However, after typing what to log I still have to either continue to type the closing parentheses or use the right arrow to put me at the end of the command. Is there a plugin so that I don't have to do that? Thanks.

console.log('hello');
                 ^ after this I have to right arrow to the end of semicolon 


Solution 1:[1]

Not sure which language but Typescript automatically comes with a snippet completion that does this. Just type 'log' and choose the snippet completion that pops up. After typing your log message you can hit Tab to go to the next line.

If your language doesn't have this or you want to customize the snippet you can create your own snippet completions. https://code.visualstudio.com/docs/editor/userdefinedsnippets#_create-your-own-snippets

If you look at the Typescript/Javascript snippet json it even has the code example for the console.log snippet completion.

"Print to console": {
        "prefix": "log",
        "body": [
            "console.log('$1');",
            "$2"
        ],
        "description": "Log output to console"
     }

When creating your own snippets I like putting short categories in the prefix itself. So if you created your own snippet based on the above, the prefix would be: "sn fn clog" (Note the spaces)

So you would prepend all your user defined snippet prefixes with 'sn '. That way if you type 'sn ' , you'll see all your custom completion pop up in the completion window. If you type 'fn ' , you'll seen all function custom snippets. Typing 'clog' will just pop up the correct custom logging snippet for you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 boocs