Reputation: 163
I used to write C code with Visual Studio, and whenever I wrote "for" and then pressed TAB, it was automatically completed to an entire for loop, i.e.
for (size_t i = 0; i < length; i++)
{
}
Is there a way to enable that in VSCode as well? Even by using some extension? Thanks!
Upvotes: 2
Views: 2516
Reputation: 1
Is there a way to enable that in VSCode as well?
Yes, you can add snippets
and customize them according to your needs if the corresponding snippet is not already available, as shown below for the for
loop shown in your question.
Go to Files -> Preferences -> User Snippets
After clicking on the User Snippets you will be prompted with a menu with different options as shown in the screen shot attached. Click on the option saying: New Global Snippets File
When you click on New Global Snippets File, a file will open where you can add your required snippet. Since you've given the for
loop that you want in C++, I will write the content that you want to place in that file:
{
"For Loop": {
"prefix": ["for", "for-const"],
"body": ["for (size_t i = ${1:0} ;i < ${2:length}; i++)", "{\t${0://add code here}", "}"],
"description": "A for loop."
}
}
Save this file with the content shown above and then you will be able to use this snippet. For example, next time you write for
you will be prompted with different options and you can press TAB
for selecting that option and that snippet will be used at that point, as shown in the below screenshot :
Upvotes: 7