In Sublime Text, multi-line code snippets can be defined with white-spaces in a snippet file.
But as far as I know, VS-Code needs a JSON entry. These require either:
\n
This is inconvenient compared to the WYSIWYG approaches other IDEs provide out of the box.
Are there better ways for defining long-blocks of code?
Select the lines you want and then press: Windows: Shift + Alt + i. Mac: shift + option + i.
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.
You can define the body of your snippet as an array of strings, each beginning on a new line.
Like this:
"Create for loop":{ "prefix": "mkfor", "body":[ "for(int i = 0; i < 3; i++)", "{", " //code goes here", "}" ], "description": "Creates a for loop" }
or if you install Easy Snippet Maker
extension, you can create your snippets by highlighting texts.
You can check out this video for a quick short tutorial
https://youtu.be/g1ouTcFxQSU
Go to File --> Preferences --> User Snippets. Select your preferred language.
Now type the following code to make a for loop snippet:
"Create for loop":{ "prefix": "for", "body":[ "for(int i = 0; i < 10; i++)", "{", " //code goes here", "}" ], "description": "Creates a for loop" }
You are done.
Type "for" in the editor and use the first prediction.
SHORTCUT--
Hope this helps :)
Note: goto File->Preferences->User Snippets. Then select the language in which you
created the snippet. You will find the snippet there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With