Visual Studio Code Add set code snippet (snippet)

Source: Internet
Author: User
Tags sublime text



Since the release of Vscode has been concerned, has recently been updated to version 0.10.8, has been supported plug-in features. Daily use of the editor has been migrated from sublime text to Vscode. In the use of the problem encountered in the Internet has not found a solution. Record your own method of groping.
1. First, you can open a C # file (or in the current open file) press the shortcut key ctrl+shift+p Open command Input snippet: (You can also click File=>preferences=>user Snippets)

Select the second option, Preferences:snippets. (I have a number of options here because I have installed another plugin for snippet.)
2. After selecting the option, a list of languages will appear to choose which language to create the code snippet, as an example of setting the Console.WriteLine code snippet for C #, the other language methods are the same.
Selecting C # automatically opens a JSON-formatted configuration file. Visual Studio code defaults to the demo. Divert.

Parameter explanation:


Prefix: This parameter is a quick entry to use the code segment. For example, if the log is used, the input log will be intellisense.
Body : This is the body of the code segment. The code to be set is placed here, and the line break between strings is separated by \r\n newline. Note that if the value contains special characters, it needs to be escaped.
$1 : This is the location of the cursor.
$2: After using this parameter, the next position of the cursor will start another line, press tab to switch quickly.
Description : description of the code segment, description when using IntelliSense 


Test the output consolewriteline () with the Console.readkey ().


1 {
  2 "ConsoleWrite with end": {
  3 "prefix": "cwe",
  4 "body": [
  5 "Console.WriteLine(‘$1‘);\r\nConsole.ReadKey();",
  6 "$2"
  7 ],
  8 "description": "output end tag(test snippet)"
  9     }
10 } 


Ctrl+s after saving in C # file Enter CWE press TAB to see the effect.


Note In the third row, when the next position using the $ $ parameter cursor will be another row, the $ $ parameter is not configurable. To this setting snippet is complete.
Tips


Visual Studio Code is different from Sublime Text (hereinafter referred to as ST) shortcuts:
     Multiple cursors are edited at the same time: Alt does not hold the mouse.
     Select the word where the cursor is: Ctrl+D. (Ctrl+Shift+L select all the places in the Chinese where the word appears)
     Quickly switch the up and down statements: Alt+Up (Up: up arrow, Ctrl+Shift+ arrow in ST)
     Quickly navigate to the defined place: F12
     Quick preview variable definition: Alt+F12 (both of these functions have been used by VS:) And the C# language supports the information that the current field/function is referenced, which can be set in editor.referenceInfos)
     Quickly copy the current line to the previous or next line: Shift+Alt+Up/Down
     Find/switch matching brackets: Ctrl+Shift+]
     Quick / Uncomment: Ctrl+/
     Quick split screen editing: Ctrl+\ 







Visual Studio Code Add set code snippet (snippet)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.