vscode 使用

lishihuan大约 10 分钟

vscode 使用

开发前设置

关闭保持自动格式化,并且设置缩进4个空格

1. 关闭保存自动格式化

image-20221122100112520

2. 设置缩进4个空格

打开 设置 搜索detectindentation

image-20221122100732947
image-20221122100732947

如果没生 参考:https://www.jianshu.com/p/90171778459copen in new window

VSCode左下角的设置图标-->设置--> 输入框中搜索settings,随便点一个

image-20221122100206274
image-20221122100206274
/*  prettier的配置 */
    "prettier.printWidth": 100, // 超过最大值换行
    "prettier.tabWidth": 4, // 缩进字节数
    "prettier.useTabs": false, // 缩进不使用tab,使用空格
    "prettier.semi": true, // 句尾添加分号
    "prettier.singleQuote": true, // 使用单引号代替双引号
    "prettier.proseWrap": "preserve", // 默认值。因为使用了一些折行敏感型的渲染器(如GitHub comment)而按照markdown文本样式进行折行
    "prettier.arrowParens": "avoid", //  (x) => {} 箭头函数参数只有一个时是否要有小括号。avoid:省略括号
    "prettier.bracketSpacing": true, // 在对象,数组括号与文字之间加空格 "{ foo: bar }"
    "prettier.disableLanguages": ["vue"], // 不格式化vue文件,vue文件的格式化单独设置
    "prettier.endOfLine": "auto", // 结尾是 \n \r \n\r auto
    "prettier.eslintIntegration": false, //不让prettier使用eslint的代码格式进行校验
    "prettier.htmlWhitespaceSensitivity": "ignore",
    "prettier.ignorePath": ".prettierignore", // 不使用prettier格式化的文件填写在项目的.prettierignore文件中
    "prettier.jsxBracketSameLine": false, // 在jsx中把'>' 是否单独放一行
    "prettier.jsxSingleQuote": false, // 在jsx中使用单引号代替双引号
    "prettier.parser": "babylon", // 格式化的解析器,默认是babylon
    "prettier.requireConfig": false, // Require a 'prettierconfig' to format prettier
    "prettier.stylelintIntegration": false, //不让prettier使用stylelint的代码格式进行校验
    "prettier.trailingComma": "es5", // 在对象或数组最后一个元素后面是否加逗号(在ES5中加尾逗号)
    "prettier.tslintIntegration": false,
    "terminal.integrated.allowMnemonics": true,
    "terminal.integrated.automationShell.linux": "" // 不让prettier使用tslint的代码格式进行校验
///报错的话,检查一下有没有用逗号与上一项设置分隔

VScode格式化代码换行问题

VSCode左下角的设置图标-->设置--> 输入框中搜索settings,随便点一个

// 添加的内容
"vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
        "wrap_line_length": 120,
        "wrap_attributes": "auto",//代码换行模式 auto   force   force-aligned   force-expand-multiline
        "end_with_newline": false
    }
},

如果使用了 prettier

123
123

vscode 在此系统上禁止运行脚本

1、关闭 vscode

2、使用管理员身份打开vscode

3、在终端中执行 set-ExecutionPolicy RemoteSigned;

4、关闭用管理员身分打开的vscode,重新普通登录用户打开vscode就可以了

vscode 开发必要的插件

  • Vetur:vue 代码提示
  • open in browser :允许您在默认浏览器中打开当前文件
  • Live Server : 启动具有实时重新加载功能的开发本地服务器
  • Auto Close Tag : 自动添加 HTML/XML 关闭标记
  • Auto Rename Tag : 自动重命名成对的 HTML/XML 标记
  • Chinese (Simplified) Language Pack for Visual Studio Code : 此中文(简体)语言包为VS Code提供本地化界面
  • ESLint: 前端检查
  • HTML CSS Support : 用于 HTML 的 CSS 智能感知
  • HTML Snippets : 完整的 HTML 标签
  • JavaScript (ES6) code snippets :ES6 语法中的 JavaScript 代码片段——语法提示
  • eclipse

快捷键设置

ctrl+shft+p 打开命令面板 输入 keyboard

配置文件的位置:C:\Users\lishihuan\AppData\Roaming\Code\User

自定义快捷键-Eclipse

格式化 ctrl+shift+f 失效,大概率是和输入法冲突(搜狗、微软输入法)

配置--没测试过

C:\Users\lishihuan\AppData\Roaming\Code\User\settings.json

{
  "files.associations": {
  "*.vue": "vue",
  "*.wpy": "vue",
  "*.wxml": "html",
  "*.wxss": "css"
  },
  "terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
  "git.enableSmartCommit": true,
  "git.autofetch": true,
  "emmet.triggerExpansionOnTab": true,
  "emmet.showAbbreviationSuggestions": true,
  "emmet.showExpandedAbbreviation": "always",
  "emmet.includeLanguages": {
  "vue-html": "html",
  "vue": "html",
  "wpy": "html"
  },
  //主题颜色 
  //"workbench.colorTheme": "Monokai",
  "git.confirmSync": false,
  "explorer.confirmDelete": false,
  "editor.fontSize": 14,
  "window.zoomLevel": 1,
  "editor.wordWrap": "on",
  "editor.detectIndentation": false,
  // 重新设定tabsize
  "editor.tabSize": 2,
  //失去焦点后自动保存
  "files.autoSave": "onFocusChange",
  // #值设置为true时,每次保存的时候自动格式化;
  "editor.formatOnSave": false,
   //每120行就显示一条线
  "editor.rulers": [
  ],
  // 在使用搜索功能时,将这些文件夹/文件排除在外
  "search.exclude": {
      "**/node_modules": true,
      "**/bower_components": true,
      "**/target": true,
      "**/logs": true,
  }, 
  // 这些文件将不会显示在工作空间中
  "files.exclude": {
      "**/.git": true,
      "**/.svn": true,
      "**/.hg": true,
      "**/CVS": true,
      "**/.DS_Store": true,
      "**/*.js": {
          "when": "$(basename).ts" //ts编译后生成的js文件将不会显示在工作空中
      },
      "**/node_modules": true
  }, 
  // #让vue中的js按"prettier"格式进行格式化
  "vetur.format.defaultFormatter.html": "js-beautify-html",
  "vetur.format.defaultFormatter.js": "prettier",
  "vetur.format.defaultFormatterOptions": {
      "js-beautify-html": {
          // #vue组件中html代码格式化样式
          "wrap_attributes": "force-aligned", //也可以设置为“auto”,效果会不一样
          "wrap_line_length": 200,
          "end_with_newline": false,
          "semi": false,
          "singleQuote": true
      },
      "prettier": {
          "semi": false,
          "singleQuote": true
      }
  }
}

二、拓展

https://github.com/varHarrie/varharrie.github.io/issues/10open in new window

名称简述
Auto Close Tagopen in new window自动闭合HTML标签
Auto Importopen in new windowimport提示
Auto Rename Tagopen in new window修改HTML标签时,自动修改匹配的标签
Babel JavaScriptopen in new windowbabel插件,语法高亮
Babelrcopen in new window.babelrc文件高亮提示
Beautify css/sass/scss/lessopen in new windowcss/sass/less格式化
Better Alignopen in new window对齐赋值符号和注释
Better Commentsopen in new window编写更加人性化的注释
Bookmarksopen in new window添加行书签
Bracket Lensopen in new window在闭合的括号处提示括号头部的代码
Bracket Pair Colorizer 2open in new window用不同颜色高亮显示匹配的括号
Can I Useopen in new windowHTML5、CSS3、SVG的浏览器兼容性检查
Code Outlineopen in new window展示代码结构树
Code Runneropen in new window运行选中代码段(支持多数语言)
Code Spell checkeropen in new window单词拼写检查
CodeBingopen in new window快速打开Bing并搜索,可配置搜索引擎
Color Highlightopen in new window颜色值在代码中高亮显示
Color Infoopen in new window小窗口显示颜色值,rgb,hsl,cmyk,hex等等
Color Pickeropen in new window拾色器
CSS-in-JSopen in new windowCSS-in-JS高亮提示和转换
Dashopen in new window集成Dash
Debugger for Chromeopen in new window调试Chrome
Document Thisopen in new window注释文档生成
DotENVopen in new window.env文件高亮
Edit csvopen in new window编辑CSV文件
EditorConfig for VS Codeopen in new windowEditorConfig插件
Emojiopen in new window在代码中输入emoji
endyopen in new window将输入光标跳转到当前行最后面
Error Guttersopen in new window在行号处提示错误代码
ESLintopen in new windowESLint插件,高亮提示
File Peekopen in new window根据路径字符串,快速定位到文件
filesizeopen in new window状态栏显示当前文件大小
Find-Jumpopen in new window快速跳转到指定单词位置
Font-awesome codes for htmlopen in new windowFontAwesome提示代码段
ftp-syncopen in new window同步文件到ftp
Git Blameopen in new window在状态栏显示当前行的Git信息
Git File Historyopen in new window快速浏览单文件历史提交变动
Git Graphopen in new windowGit图形化视图,方便浏览和操作
Git History(git log)open in new window查看git log
Git Tree Compareopen in new windowGit树形比对,查看不同分支的差异
gitignoreopen in new window.gitignore文件语法
GitLensopen in new window显示文件最近的commit和作者,显示当前行commit信息
GraphQL for VSCodeopen in new windowgraphql高亮和提示
Guidesopen in new window高亮缩进基准线
Gulp Snippetsopen in new windowGulp代码段
Highlight Matching Tagopen in new window高亮匹配选中的标签
HTML CSS Class Completionopen in new windowCSS class提示
HTML CSS Supportopen in new windowcss提示(支持vue)
HTMLHintopen in new windowHTML格式提示
htmltagwrapopen in new window快捷包裹html标签
htmltagwrapopen in new window包裹HTML
Import Beautifyopen in new windowimport分组、排序、格式化
Import Costopen in new window行内显示导入(import/require)的包的大小
Indenticatoropen in new window缩进高亮
IntelliSense for css class namesopen in new windowcss class输入提示
JavaScript (ES6) code snippetsopen in new windowES6语法代码段
JavaScript Standard Styleopen in new windowStandard风格
Jest Runneropen in new window支持执行Jest单个测试文件或单个用例
JS Refactoropen in new window代码重构工具,提取函数、变量重命名等等
JSON to TSopen in new windowJSON结构转化为typescript的interface
JSON Toolsopen in new window格式化和压缩JSON
jumpyopen in new window快速跳转到指定单词位置
language-stylusopen in new windowStylus语法高亮和提示
Less IntelliSenseopen in new windowless变量与混合提示
Lodashopen in new windowLodash代码段
Log Wrapperopen in new window生产打印选中变量的代码
markdownlintopen in new windowMarkdown格式提示
MochaSnippetsopen in new windowMocha代码段
Node modules resolveopen in new window快速导航到Node模块
npmopen in new window运行npm命令
npm Intellisenseopen in new window导入模块时,提示已安装模块名称
Output Colorizeropen in new window彩色输出信息
Partial Diffopen in new window对比两段代码或文件
Parameter Hintsopen in new window在函数调用处指示参数名称
Path Autocompleteopen in new window路径完成提示
Path Intellisenseopen in new window另一个路径完成提示
Polacodeopen in new window将代码生成图片
PostCss Sortingopen in new windowcss排序
Prettier - Code formatteropen in new windowprettier官方插件
Prettify JSONopen in new window格式化JSON
Project Manageropen in new window快速切换项目
Quokka.jsopen in new window不需要手动运行,行内显示变量结果
Rainbow CSVopen in new windowCSV文件使用彩虹色渲染不同列
React Native Storybooksopen in new windowstorybook预览插件,支持react
React Playgroundopen in new window为编辑器提供一个react组件运行环境,方便调试
React Standard Style code snippetsopen in new windowreact standar风格代码块
REST Clientopen in new window发送REST风格的HTTP请求
Sassopen in new windowsass插件
Settings Syncopen in new windowVSCode设置同步到Gist
Sort linesopen in new window排序选中行
Sort Typescript Importsopen in new windowtypescript的import排序
String Manipulationopen in new window字符串转换处理(驼峰、大写开头、下划线等等)
stylelintopen in new windowcss/sass/less代码风格
SVG Vieweropen in new windowSVG查看器
Syncingopen in new windowvscode设置同步到gist
Test Spec Generatoropen in new window测试用例生成(支持chai、should、jasmine)
TODO Parseropen in new windowTodo管理
Todo Todo Treeopen in new window收集代码中的TODO注释,支持快速搜索
Toggle Quotesopen in new window切换JS中的引号," -> ' -> `
TS/JS postfix completionopen in new windowts/js后缀提示
TSLintopen in new windowTypeScript语法检查
Types auto installeropen in new window自动安装@typesopen in new window声明依赖
TypeScript Heroopen in new windowTypeScript辅助插件,管理import、outline等等
TypeScript Importopen in new windowTS自动import
TypeScript Import Sorteropen in new windowimport整理排序
Typescript React code snippetsopen in new windowReact Typescript代码段
TypeSearchopen in new windowTS声明文件搜索
Version Lensopen in new windowpackage.json文件显示模块当前版本和最新版本
veturopen in new windowVue插件
Volaropen in new windowVue插件,支持Vue3
View Node Packageopen in new window快速打开选中模块的主页和代码仓库
Visual Studio IntelliCodeopen in new window基于AI的代码提示
VS Live Shareopen in new window实时多人协助
VSCode Great Iconsopen in new window文件图标拓展
vscode-databaseopen in new window操作数据库,支持mysql和postgres
vscode-iconsopen in new window文件图标,方便定位文件
vscode-randomopen in new window随机字符串生成器
vscode-spotifyopen in new window集成spotify,播放音乐
vscode-styled-componentsopen in new windowstyled-components高亮支持
vscode-styled-jsxopen in new windowstyled-jsx高亮支持
Vue Peekopen in new window支持跳转到Vue组件定义文件
Vue TypeScript Snippetsopen in new windowVue Typescript代码段
VueHelperopen in new windowVue2代码段(包括Vue2 api、vue-router2、vuex2)
Wallaby.jsopen in new window实时测试插件
Wrap Console Log Liteopen in new window对选中代码快速console.log

三、主题