• MetaDescription: How to modify Visual Studio Code User and Workspace Settings.
  • 用户和工作区设置(User and Workspace Settings)
    • 创建用户和工作区设置(Creating User and Workspace Settings)
    • 设置文件的位置(Settings File Locations)
    • 设置文件内容(Settings File Sections)
    • 默认设置(Default Settings)
    • Common Questions

    Order: 2
    Area: customization
    TOCTitle: User and Workspace Settings
    ContentId: FDA6D86C-FF24-49BC-A1EB-E3BA43130FA0
    PageTitle: Visual Studio Code User and Workspace Settings
    DateApproved: 4/14/2016

    MetaDescription: How to modify Visual Studio Code User and Workspace Settings.

    用户和工作区设置(User and Workspace Settings)

    It’s easy to configure VS Code the way you want by editing the various setting files where you will find a great number of settings to play with.

    很容易通过编辑各种设置文件来配置VS Code,你会发现许多有意思的设置。

    VS Code provides two different scopes for settings:

    VS Code 的设置分为两种作用域:

    • User these settings apply globally to any instance of VS Code you open
    • Workspace these settings are stored inside your workspace in a .vscode folder and only apply when the workspace is opened. Settings defined on this scope overwrite the user scope.

    • 用户设置 这些设置全局应用于您打开的任何VS Code 项目

    • 工作区设置 这些设置存储在工作区内的 .vscode 文件夹中,并且仅在打开的工作区适用。在此范围上定义的设置将覆盖用户范围的设置。

    创建用户和工作区设置(Creating User and Workspace Settings)

    The menu under File > Preferences provides entries to configure user and workspace settings. You are provided with a list of Default Settings. Copy any setting that you want to change to the related settings.json file.

    文件>首选项 下的 菜单 提供用于配置用户和工作空间设置的选项。您将看到一个默认设置列表。将要更改的任何设置复制到相关的(右侧) settings.json 文件。

    In the example below, we disabled line numbers in the editor and configured line wrapping to wrap automatically based on the size of the editor.

    如下面的示例,我们在编辑器中禁用了 行号 ,并且配置换行为根据编辑器的大小自动换行。

    Example Settings

    Changes to settings are reloaded by VS Code after the modified settings.json file is saved.

    保存修改的 settings.json 文件后,VS Code 将重新加载对设置的更改。

    设置文件的位置(Settings File Locations)

    Depending on your platform, the user settings file is located here:

    根据您的操作系统,用户设置文件位于下面几处:

    • Windows %APPDATA%\Code\User\settings.json
    • Mac $HOME/Library/Application Support/Code/User/settings.json
    • Linux $HOME/.config/Code/User/settings.json

    The workspace setting file is located under the .vscode folder in your project.

    工作区设置文件位于项目中的 .vscode 文件夹下。

    设置文件内容(Settings File Sections)

    The settings.json file is divided into these sections:

    settings.json 文件分为以下几个部分:

    • Editor Configuration - font, word wrapping, tab size, line numbers, indentation, …
    • Window Configuration - restore folders, zoom level, …
    • Files Configuration - excluded file filters, default encoding, trim trailing whitespace, …
    • File Explorer Configuration - encoding, WORKING FILES behavior, …
    • HTTP Configuration - proxy settings
    • Search Configuration - file exclude filters
    • Git Configuration - disable Git integration, auto fetch behavior
    • Telemetry Configuration - disable telemetry reporting, crash reporting
    • HTML Configuration - HTML format configuration
    • CSS Configuration - CSS linting configuration
    • JavaScript Configuration - Language specific settings
    • JSON Configuration - Schemas associated with certain JSON files
    • Markdown Preview Configuration - Add a custom CSS to the Markdown preview
    • Less Configuration - Control linting for Less
    • Sass Configuration - Control linting for Sass
    • TypeScript Configuration - Language specific settings
    • PHP Configuration - PHP linter configuration

    默认设置(Default Settings)

    Below is a copy of the default settings.json file.

    下面是默认的 settings.json 文件的实例。

    Tip: While in the settings.json file, press kb(workbench.action.gotoSymbol) to see an outline of all available settings and navigate through the file.

    提示:settings.json 文件中,按 kb(workbench.action.gotoSymbol) 可查看所有可用设置的大纲,并浏览该文件。

    1. // Overwrite settings by placing them into your settings file.
    2. {
    3. //-------- Editor configuration --------
    4. // Controls the font family.
    5. "editor.fontFamily": "",
    6. // Controls the font size.
    7. "editor.fontSize": 0,
    8. // Controls the line height.
    9. "editor.lineHeight": 0,
    10. // Controls visibility of line numbers
    11. "editor.lineNumbers": true,
    12. // Controls visibility of the glyph margin
    13. "editor.glyphMargin": false,
    14. // Columns at which to show vertical rulers
    15. "editor.rulers": [],
    16. // Characters that will be used as word separators when doing word related navigations or operations
    17. "editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\|;:'\",.<>/?",
    18. // The number of spaces a tab is equal to.
    19. "editor.tabSize": 4,
    20. // Insert spaces when pressing Tab.
    21. "editor.insertSpaces": true,
    22. // When opening a file, `editor.tabSize` and `editor.insertSpaces` will be detected based on the file contents.
    23. "editor.detectIndentation": true,
    24. // Controls if selections have rounded corners
    25. "editor.roundedSelection": true,
    26. // Controls if the editor will scroll beyond the last line
    27. "editor.scrollBeyondLastLine": true,
    28. // Controls after how many characters the editor will wrap to the next line. Setting this to 0 turns on viewport width wrapping
    29. "editor.wrappingColumn": 300,
    30. // Controls the indentation of wrapped lines. Can be one of 'none', 'same' or 'indent'.
    31. "editor.wrappingIndent": "same",
    32. // A multiplier to be used on the `deltaX` and `deltaY` of mouse wheel scroll events
    33. "editor.mouseWheelScrollSensitivity": 1,
    34. // Controls if quick suggestions should show up or not while typing
    35. "editor.quickSuggestions": true,
    36. // Controls the delay in ms after which quick suggestions will show up
    37. "editor.quickSuggestionsDelay": 10,
    38. // Controls if the editor should automatically close brackets after opening them
    39. "editor.autoClosingBrackets": true,
    40. // Controls if the editor should automatically format the line after typing
    41. "editor.formatOnType": false,
    42. // Controls if suggestions should automatically show up when typing trigger characters
    43. "editor.suggestOnTriggerCharacters": true,
    44. // Controls if suggestions should be accepted 'Enter' - in addition to 'Tab'. Helps to avoid ambiguity between inserting new lines or accepting suggestions.
    45. "editor.acceptSuggestionOnEnter": true,
    46. // Controls whether the editor should highlight similar matches to the selection
    47. "editor.selectionHighlight": true,
    48. // Controls the number of decorations that can show up at the same position in the overview ruler
    49. "editor.overviewRulerLanes": 3,
    50. // Controls the cursor blinking animation, accepted values are 'blink', 'visible', and 'hidden'
    51. "editor.cursorBlinking": "blink",
    52. // Controls the cursor style, accepted values are 'block' and 'line'
    53. "editor.cursorStyle": "line",
    54. // Enables font ligatures
    55. "editor.fontLigatures": false,
    56. // Controls if the cursor should be hidden in the overview ruler.
    57. "editor.hideCursorInOverviewRuler": false,
    58. // Controls whether the editor should render whitespace characters
    59. "editor.renderWhitespace": false,
    60. // Controls if the editor shows reference information for the modes that support it
    61. "editor.referenceInfos": true,
    62. // Controls whether the editor has code folding enabled
    63. "editor.folding": true,
    64. // Controls if the diff editor shows the diff side by side or inline
    65. "diffEditor.renderSideBySide": true,
    66. // Controls if the diff editor shows changes in leading or trailing whitespace as diffs
    67. "diffEditor.ignoreTrimWhitespace": true,
    68. //-------- Window configuration --------
    69. // When enabled, will open files in a new window instead of reusing an existing instance.
    70. "window.openFilesInNewWindow": true,
    71. // Controls how folders are being reopened after a restart. Select 'none' to never reopen a folder, 'one' to reopen the last folder you worked on or 'all' to reopen all folders of your last session.
    72. "window.reopenFolders": "one",
    73. // Adjust the zoom level of the window. The original size is 0 and each increment above (e.g. 1) or below (e.g. -1) represents zooming 20% larger or smaller. You can also enter decimals to adjust the zoom level with a finer granularity.
    74. "window.zoomLevel": 0,
    75. //-------- Files configuration --------
    76. // Configure glob patterns for excluding files and folders.
    77. "files.exclude": {
    78. "**/.git": true,
    79. "**/.DS_Store": true
    80. },
    81. // Configure file associations to languages (e.g. "*.extension": "html"). These have precedence over the default associations of the languages installed.
    82. "files.associations": {},
    83. // The default character set encoding to use when reading and writing files.
    84. "files.encoding": "utf8",
    85. // The default end of line character.
    86. "files.eol": "\n",
    87. // When enabled, will trim trailing whitespace when you save a file.
    88. "files.trimTrailingWhitespace": false,
    89. // Controls auto save of dirty files. Accepted values: "off", "afterDelay", "onFocusChange". If set to "afterDelay" you can configure the delay in "files.autoSaveDelay".
    90. "files.autoSave": "off",
    91. // Controls the delay in ms after which a dirty file is saved automatically. Only applies when "files.autoSave" is set to "afterDelay"
    92. "files.autoSaveDelay": 1000,
    93. // Configure glob patterns of file paths to exclude from file watching. Changing this setting requires a restart. When you experience Code consuming lots of cpu time on startup, you can exclude large folders to reduce the initial load.
    94. "files.watcherExclude": {
    95. "**/.git/objects/**": true,
    96. "**/node_modules/**": true
    97. },
    98. //-------- File Explorer configuration --------
    99. // Maximum number of working files to show before scrollbars appear.
    100. "explorer.workingFiles.maxVisible": 9,
    101. // Controls if the height of the working files section should adapt dynamically to the number of elements or not.
    102. "explorer.workingFiles.dynamicHeight": true,
    103. //-------- HTTP configuration --------
    104. // The proxy setting to use. If not set will be taken from the http_proxy and https_proxy environment variables
    105. "http.proxy": "",
    106. // Whether the proxy server certificate should be verified against the list of supplied CAs.
    107. "http.proxyStrictSSL": true,
    108. //-------- Update configuration --------
    109. // Configure the update channel to receive updates from. Requires a restart after change.
    110. "update.channel": "default",
    111. //-------- Search configuration --------
    112. // Configure glob patterns for excluding files and folders in searches. Inherits all glob patterns from the file.exclude setting.
    113. "search.exclude": {
    114. "**/node_modules": true,
    115. "**/bower_components": true
    116. },
    117. //-------- Git configuration --------
    118. // Is git enabled
    119. "git.enabled": true,
    120. // Path to the git executable
    121. "git.path": null,
    122. // Whether auto fetching is enabled.
    123. "git.autofetch": true,
    124. //-------- Telemetry configuration --------
    125. // Enable usage data and errors to be sent to Microsoft.
    126. "telemetry.enableTelemetry": true,
    127. //-------- Markdown preview configuration --------
    128. // A list of URLs or local paths to CSS style sheets to use from the markdown preview.
    129. "markdown.styles": [],
    130. //-------- JSON configuration --------
    131. // Associate schemas to JSON files in the current project
    132. "json.schemas": [],
    133. //-------- HTML configuration --------
    134. // Maximum amount of characters per line (0 = disable).
    135. "html.format.wrapLineLength": 120,
    136. // List of tags, comma separated, that shouldn't be reformatted. 'null' defaults to all inline tags.
    137. "html.format.unformatted": null,
    138. // Indent <head> and <body> sections.
    139. "html.format.indentInnerHtml": false,
    140. // Whether existing line breaks before elements should be preserved. Only works before elements, not inside tags or for text.
    141. "html.format.preserveNewLines": true,
    142. // Maximum number of line breaks to be preserved in one chunk. Use 'null' for unlimited.
    143. "html.format.maxPreserveNewLines": null,
    144. // Format and indent {{#foo}} and {{/foo}}.
    145. "html.format.indentHandlebars": false,
    146. // End with a newline.
    147. "html.format.endWithNewline": false,
    148. // List of tags, comma separated, that should have an extra newline before them. 'null' defaults to "head, body, /html".
    149. "html.format.extraLiners": null,
    150. //-------- Telemetry configuration --------
    151. // Enable crash reports to be sent to Microsoft.
    152. // This option requires restart to take effect.
    153. "telemetry.enableCrashReporter": true,
    154. //-------- CSS configuration --------
    155. // Controls CSS validation and problem severities.
    156. // Enables or disables all validations
    157. "css.validate": true,
    158. // When using a vendor-specific prefix make sure to also include all other vendor-specific properties
    159. "css.lint.compatibleVendorPrefixes": "ignore",
    160. // When using a vendor-specific prefix also include the standard property
    161. "css.lint.vendorPrefix": "warning",
    162. // Do not use duplicate style definitions
    163. "css.lint.duplicateProperties": "ignore",
    164. // Do not use empty rulesets
    165. "css.lint.emptyRules": "warning",
    166. // Import statements do not load in parallel
    167. "css.lint.importStatement": "ignore",
    168. // Do not use width or height when using padding or border
    169. "css.lint.boxModel": "ignore",
    170. // The universal selector (*) is known to be slow
    171. "css.lint.universalSelector": "ignore",
    172. // No unit for zero needed
    173. "css.lint.zeroUnits": "ignore",
    174. // @font-face rule must define 'src' and 'font-family' properties
    175. "css.lint.fontFaceProperties": "warning",
    176. // Hex colors must consist of three or six hex numbers
    177. "css.lint.hexColorLength": "error",
    178. // Invalid number of parameters
    179. "css.lint.argumentsInColorFunction": "error",
    180. // Unknown property.
    181. "css.lint.unknownProperties": "warning",
    182. // IE hacks are only necessary when supporting IE7 and older
    183. "css.lint.ieHack": "ignore",
    184. // Unknown vendor specific property.
    185. "css.lint.unknownVendorSpecificProperties": "ignore",
    186. // Property is ignored due to the display. E.g. with 'display: inline', the width, height, margin-top, margin-bottom, and float properties have no effect
    187. "css.lint.propertyIgnoredDueToDisplay": "warning",
    188. // Avoid using !important. It is an indication that the specificity of the entire CSS has gotten out of control and needs to be refactored.
    189. "css.lint.important": "ignore",
    190. // Avoid using 'float'. Floats lead to fragile CSS that is easy to break if one aspect of the layout changes.
    191. "css.lint.float": "ignore",
    192. // Selectors should not contain IDs because these rules are too tightly coupled with the HTML.
    193. "css.lint.idSelector": "ignore",
    194. //-------- LESS configuration --------
    195. // Controls LESS validation and problem severities.
    196. // Enables or disables all validations
    197. "less.validate": true,
    198. // When using a vendor-specific prefix make sure to also include all other vendor-specific properties
    199. "less.lint.compatibleVendorPrefixes": "ignore",
    200. // When using a vendor-specific prefix also include the standard property
    201. "less.lint.vendorPrefix": "warning",
    202. // Do not use duplicate style definitions
    203. "less.lint.duplicateProperties": "ignore",
    204. // Do not use empty rulesets
    205. "less.lint.emptyRules": "warning",
    206. // Import statements do not load in parallel
    207. "less.lint.importStatement": "ignore",
    208. // Do not use width or height when using padding or border
    209. "less.lint.boxModel": "ignore",
    210. // The universal selector (*) is known to be slow
    211. "less.lint.universalSelector": "ignore",
    212. // No unit for zero needed
    213. "less.lint.zeroUnits": "ignore",
    214. // @font-face rule must define 'src' and 'font-family' properties
    215. "less.lint.fontFaceProperties": "warning",
    216. // Hex colors must consist of three or six hex numbers
    217. "less.lint.hexColorLength": "error",
    218. // Invalid number of parameters
    219. "less.lint.argumentsInColorFunction": "error",
    220. // Unknown property.
    221. "less.lint.unknownProperties": "warning",
    222. // IE hacks are only necessary when supporting IE7 and older
    223. "less.lint.ieHack": "ignore",
    224. // Unknown vendor specific property.
    225. "less.lint.unknownVendorSpecificProperties": "ignore",
    226. // Property is ignored due to the display. E.g. with 'display: inline', the width, height, margin-top, margin-bottom, and float properties have no effect
    227. "less.lint.propertyIgnoredDueToDisplay": "warning",
    228. // Avoid using !important. It is an indication that the specificity of the entire CSS has gotten out of control and needs to be refactored.
    229. "less.lint.important": "ignore",
    230. // Avoid using 'float'. Floats lead to fragile CSS that is easy to break if one aspect of the layout changes.
    231. "less.lint.float": "ignore",
    232. // Selectors should not contain IDs because these rules are too tightly coupled with the HTML.
    233. "less.lint.idSelector": "ignore",
    234. //-------- Sass configuration --------
    235. // Controls Sass validation and problem severities.
    236. // Enables or disables all validations
    237. "sass.validate": true,
    238. // When using a vendor-specific prefix make sure to also include all other vendor-specific properties
    239. "sass.lint.compatibleVendorPrefixes": "ignore",
    240. // When using a vendor-specific prefix also include the standard property
    241. "sass.lint.vendorPrefix": "warning",
    242. // Do not use duplicate style definitions
    243. "sass.lint.duplicateProperties": "ignore",
    244. // Do not use empty rulesets
    245. "sass.lint.emptyRules": "warning",
    246. // Import statements do not load in parallel
    247. "sass.lint.importStatement": "ignore",
    248. // Do not use width or height when using padding or border
    249. "sass.lint.boxModel": "ignore",
    250. // The universal selector (*) is known to be slow
    251. "sass.lint.universalSelector": "ignore",
    252. // No unit for zero needed
    253. "sass.lint.zeroUnits": "ignore",
    254. // @font-face rule must define 'src' and 'font-family' properties
    255. "sass.lint.fontFaceProperties": "warning",
    256. // Hex colors must consist of three or six hex numbers
    257. "sass.lint.hexColorLength": "error",
    258. // Invalid number of parameters
    259. "sass.lint.argumentsInColorFunction": "error",
    260. // Unknown property.
    261. "sass.lint.unknownProperties": "warning",
    262. // IE hacks are only necessary when supporting IE7 and older
    263. "sass.lint.ieHack": "ignore",
    264. // Unknown vendor specific property.
    265. "sass.lint.unknownVendorSpecificProperties": "ignore",
    266. // Property is ignored due to the display. E.g. with 'display: inline', the width, height, margin-top, margin-bottom, and float properties have no effect
    267. "sass.lint.propertyIgnoredDueToDisplay": "warning",
    268. // Avoid using !important. It is an indication that the specificity of the entire CSS has gotten out of control and needs to be refactored.
    269. "sass.lint.important": "ignore",
    270. // Avoid using 'float'. Floats lead to fragile CSS that is easy to break if one aspect of the layout changes.
    271. "sass.lint.float": "ignore",
    272. // Selectors should not contain IDs because these rules are too tightly coupled with the HTML.
    273. "sass.lint.idSelector": "ignore",
    274. //-------- TypeScript configuration --------
    275. // Specifies the folder path containing the tsserver and lib*.d.ts files to use.
    276. "typescript.tsdk": null,
    277. // Complete functions with their parameter signature.
    278. "typescript.useCodeSnippetsOnMethodSuggest": false,
    279. // Enable / disable TypeScript validation
    280. "typescript.validate.enable": true,
    281. // Defines space handling after a comma delimiter
    282. "typescript.format.insertSpaceAfterCommaDelimiter": true,
    283. // Defines space handling after a semicolon in a for statement
    284. "typescript.format.insertSpaceAfterSemicolonInForStatements": true,
    285. // Defines space handling after a binary operator
    286. "typescript.format.insertSpaceBeforeAndAfterBinaryOperators": true,
    287. // Defines space handling after keywords in control flow statement
    288. "typescript.format.insertSpaceAfterKeywordsInControlFlowStatements": true,
    289. // Defines space handling after function keyword for anonymous functions
    290. "typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true,
    291. // Defines space handling after opening and before closing non empty parenthesis
    292. "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
    293. // Defines space handling after opening and before closing non empty brackets
    294. "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
    295. // Defines whether an open brace is put onto a new line for functions or not
    296. "typescript.format.placeOpenBraceOnNewLineForFunctions": false,
    297. // Defines whether an open brace is put onto a new line for control blocks or not
    298. "typescript.format.placeOpenBraceOnNewLineForControlBlocks": false,
    299. // Enable / disable JavaScript validation
    300. "javascript.validate.enable": true,
    301. // Defines space handling after a comma delimiter
    302. "javascript.format.insertSpaceAfterCommaDelimiter": true,
    303. // Defines space handling after a semicolon in a for statement
    304. "javascript.format.insertSpaceAfterSemicolonInForStatements": true,
    305. // Defines space handling after a binary operator
    306. "javascript.format.insertSpaceBeforeAndAfterBinaryOperators": true,
    307. // Defines space handling after keywords in control flow statement
    308. "javascript.format.insertSpaceAfterKeywordsInControlFlowStatements": true,
    309. // Defines space handling after function keyword for anonymous functions
    310. "javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true,
    311. // Defines space handling after opening and before closing non empty parenthesis
    312. "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
    313. // Defines space handling after opening and before closing non empty brackets
    314. "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
    315. // Defines whether an open brace is put onto a new line for functions or not
    316. "javascript.format.placeOpenBraceOnNewLineForFunctions": false,
    317. // Defines whether an open brace is put onto a new line for control blocks or not
    318. "javascript.format.placeOpenBraceOnNewLineForControlBlocks": false,
    319. //-------- PHP Configuration options --------
    320. // Whether php validation is enabled or not.
    321. "php.validate.enable": true,
    322. // Points to the php executable.
    323. "php.validate.executablePath": null,
    324. // Whether the linter is run on save or on type.
    325. "php.validate.run": "onSave"
    326. }

    Common Questions

    Q: When does it make sense to use workspace settings?

    A: If you’re using a workspace that needs custom settings but you don’t want to apply them to your other VS Code projects. A good example is language-specific linting rules.