Home > Back-end >  VSCode - autocomplete for loops
VSCode - autocomplete for loops

Time:06-01

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!

CodePudding user response:

Is there a way to enable that in VSCode as well?

Yes, you can add snippets and image 1

Step 3

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."
  }
}

Step 4

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:

sc 2

sc3

  • Related