跳转到内容

VS Code

vscode快捷键

参考别人的整理:https://www.cnblogs.com/ljhdo/p/13373208.html

用得最多的快捷键

光标移动到最前面/后面: ctrl + home / end

打开/关闭终端:ctrl + ` (1左边的按键) Mac下是 Command + j

区块列选择,在N列前插入相同的内容:alt + shift

按名称搜索文件,打开指定文件:ctrl + p

顺序切换tab:ctrl + pageup / pagedown

打开主侧边栏: ctrl+b

跳转到第N行:ctrl + g

关闭文件:ctrl+w

跳转到定义:f12

格式化代码:ctrl + shift + i

移动行:alt + 上下

焦点聚焦到主侧边栏: ctrl + 0 (1是聚焦回代码区)

One Dark Pro主题

耐看的深色系主题,插件商店里搜索One Dark Pro,安装然后左下角设置-主题更换即可。

简繁体转换

安装插件:opencclint

vscode settings配置:

json
  "opencclint.autoFixOnSave": true,
  "opencclint.converterOptions": "cn=>hk",

项目根目录新建配置:

js
// opencclint.config.ts
export default {
  extends: [
    'opencclint-config'
  ],
  conversion: {
    from: 'cn',
    to: 'hk',
  },
  ignoreWords: [
    '台'
  ],
  exclude: [
    '*.min.*',
    '*.d.ts',
    'CHANGELOG.md',
    'dist',
    'LICENSE*',
    'output',
    'out',
    'coverage',
    'public',
    'temp',
    'package-lock.json',
    'pnpm-lock.yaml',
    'yarn.lock',
    '__snapshots__',
    '.github',
    '.vitepress',
    '.vscode',
    'node_modules',
    'opencclint.*',
  ],
  fix: true,
}

设置自动格式化后,在当前配置文件保存时可能会报错,忽略之,其他文件保存不报错即可。

字体设置

Windows:

json
"editor.fontFamily": "LXGW WenKai,Iosevka,JetBrains Mono,HONOR Sans Cn,Consolas",
"terminal.integrated.fontFamily": "LXGW WenKai Mono",

Windwos终端字体,要设置成兼容宽体的字体,中文比较少,可以设置成LXGW WenKai Mono。正文字体可以设置成LXGW WenKai

json
"editor.fontFamily": "Iosevka,LXGW WenKai,JetBrains Mono,HONOR Sans Cn,Consolas,monospace",
"terminal.integrated.fontFamily": "Iosevka,LXGW WenKai Mono,JetBrains Mono,monospace",

Mac下面英文设置为Iosevka更为美观。中文设置为LXGW WenKai或者LXGW WenKai Mono

设置字体大小与间距,终端下间距最好设置大一些,不会看着很拥挤,以下是Mac下的配置:

json
"editor.fontSize": 12.5,
"terminal.integrated.fontSize": 12,
"terminal.integrated.lineHeight": 1.2,

设置字体前,记得确保相应的字体已安装。

LXGW开源字体下载地址:

关于web字体的选择,参考资料:

格式化python代码

安装:

bash
pip install black isort

vscode安装插件:

ms-python.black-formatter(用于Black格式化)

ms-python.isort(用于import排序)

settings.json配置:

// Python 配置
  "[python]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "ms-python.black-formatter",
    "editor.formatOnType": true,
    "editor.codeActionsOnSave": {
      "source.organizeImports": "explicit"
    }
  },
  "isort.path": ["isort"],
  "black-formatter.args": [
    "--line-length",
    "100"
  ],
  "isort.args": [
    "--profile",
    "black",
    "--line-length",
    "100"
  ],
  "files.insertFinalNewline": true,

设置光标移动和动画

设置里面搜索:

  • 将"Cursor Smooth Caret Animation" 设置为 "on"
  • 将"Cursor Blinking" 设置为 "smooth"

设置好以后光标的移动确实流畅了一些。

vscode编辑Markdown设置

通用性自动换行设置:

json
"editor.rulers": [100],
"editor.wordWrap": "wordWrapColumn",
"editor.wordWrapColumn": 100,

以上并不是默认对所有的文件生效,需要针对特定的文件类型做设置,比如Markdown需要单独设置:

json
"[markdown]": {
    "editor.wordWrap": "wordWrapColumn"
},

插件 Paste Image

快捷键:ctrl+alt+v,粘贴图片到当前文件中,并自动生成图片路径

配置图片路径:

在这个位置后面加上自己想存放的目录路径,使用相对路径,这里是增加了/../../img/

其他的不用动,保存即可。

vscode默认换行符

设置为\n,即LF。

批量修改换行符

bash
npm install --save-dev --save-exact prettier
npx prettier --write --end-of-line lf .

crlf 是windows的换行符,lf是linux的换行符。执行以后就可以批量换成lf了。

提取扩展时出错 failed to fetch

该错误跟代理有关,出错时关掉代理,或者打开代理即可,反向操作。

文件编码自动检测

终端UTF-8 配置

参考:https://zhuanlan.zhihu.com/p/688941159

实际采用:setting.json的方式。

json
"terminal.integrated.profiles.windows": {
    "PowerShell -NoProfile": {
      "source": "PowerShell",
      "args": ["-NoProfile",
        "-NoExit",
        "-Command",
        "chcp 65001"
       ]
    }
  },
  "terminal.integrated.defaultProfile.windows": "PowerShell -NoProfile",

重要参数配置

code-runner.runInTerminal 参数:

开启则在vscode终端执行,windows下不需要输入参数的话,可以关闭;然后就会在输出界面输出结果。

vscode输出界面每次运行时自动清屏后再输出,这样每次都能定位到最新的输出(最后一行) ,配置参数:

.editorconfig文件使用示例

使用示例:

yaml
# http://editorconfig.org
# vscode 安装 EditorConfig for VS Code 插件,该插件会自动读取项目的 .editorconfig 文件,对项目进行配置

root = true

[*] # 表示所有文件适用
charset = utf-8 # 设置文件字符集为 utf-8
indent_style = space # 缩进风格(tab | space)
indent_size = 4 # 缩进大小
end_of_line = lf # 控制换行类型(lf | cr | crlf)
trim_trailing_whitespace = true # 去除行首的任意空白字符
insert_final_newline = true # 始终在文件末尾插入一个新行

[*.md] # 表示仅 md 文件适用以下规则
max_line_length = off
trim_trailing_whitespace = false

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# 4 space indentation 控制py文件类型的缩进大小
[*.py]
indent_style = space
indent_size = 4

[{*.js,*.css,*.html,*.mjs,*.json,*.yml}]
indent_style = space
indent_size = 4

[{*.css}]
indent_style = space
indent_size = 2

settings.json - Windows

json
{
    "workbench.colorTheme": "One Dark Pro",
    "editor.detectIndentation": false,
    "editor.tabSize": 4,
    "editor.insertSpaces": true,
    "editor.renderControlCharacters": true,
    "editor.renderWhitespace": "selection",
    "editor.fontFamily": "Iosevka,JetBrains Mono,HONOR Sans Cn,Consolas,monospace",
    "terminal.integrated.fontFamily": "JetBrains Mono,monospace",
    "terminal.integrated.fontWeight": "normal",
    "editor.fontSize": 17,
    "terminal.integrated.fontSize": 15,
    "editor.fontLigatures": false,
    "editor.fontVariations": false,
    "editor.tokenColorCustomizations": {
        "textMateRules": [
            {
                "scope": "comment",
                "settings": {
                    "fontStyle": "italic"
                }
            }
        ]
    },
    "editor.rulers": [80],
    "editor.wordWrap": "wordWrapColumn",
    "editor.wordWrapColumn": 80,
    "files.autoGuessEncoding": true,
    "files.autoSave": "afterDelay",
    "files.autoSaveDelay": 1000,
    "editor.defaultFormatter": "xaver.clang-format",
    "editor.formatOnSave": true,
    "editor.formatOnSaveMode": "file",
    "editor.formatOnPaste": true,
    "files.trimTrailingWhitespace": true,
    "editor.minimap.enabled": true,
    "C_Cpp.default.cppStandard": "c++17",
    "C_Cpp.default.cStandard": "c17",
    "C_Cpp.formatting": "clangFormat",
    "[c]": {
        "editor.defaultFormatter": "xaver.clang-format"
    },
    "[python]": {
        "editor.formatOnType": true
    },
    "python.defaultInterpreterPath": "C:\\miniconda3\\python.exe",
    "code-runner.executorMap": {
        "c": "cd $dir && gcc -std=c17 -g -Wall $fileName -o D:\\TMP\\BUILD\\$fileNameWithoutExt.exe && D:\\TMP\\BUILD\\$fileNameWithoutExt.exe",
        "cpp": "cd $dir && g++ -std=c++17 -g -Wall $fileName -o D:\\TMP\\BUILD\\$fileNameWithoutExt.exe && D:\\TMP\\BUILD\\$fileNameWithoutExt.exe"
    },
    "code-runner.saveFileBeforeRun": true,
    "code-runner.fileDirectoryAsCwd": true,
    "code-runner.saveAllFilesBeforeRun": true,
    "code-runner.runInTerminal": true,
    "code-runner.clearPreviousOutput": true,
    "debug.terminal.clearBeforeReusing": true,
    "doxdocgen.file.copyrightTag": ["@copyright Copyright (c) {year}"],
    "doxdocgen.file.fileTemplate": "@file {name}",
    "doxdocgen.file.versionTag": "@version 1.0",
    "doxdocgen.generic.authorEmail": "[email protected]",
    "doxdocgen.generic.authorName": "huping",
    "doxdocgen.generic.authorTag": "@author {author} ({email})",
    "doxdocgen.generic.order": ["brief", "tparam", "param", "return"],
    "doxdocgen.generic.paramTemplate": "@param {param}",
    "doxdocgen.generic.returnTemplate": "@return {type}",
    "doxdocgen.generic.splitCasingSmartText": true,
    "doxdocgen.file.fileOrder": ["file", "brief", "version", "date", "author", "copyright"],
    "terminal.integrated.profiles.windows": {
        "PowerShell -NoProfile": {
            "source": "PowerShell",
            "args": ["-NoProfile", "-NoExit", "-Command", "chcp 65001"]
        }
    },
    "terminal.integrated.defaultProfile.windows": "PowerShell -NoProfile",
    "files.associations": {},
    "files.exclude": {
        "**/*.exe": true,
        "**/build": true,
        "**/.git": true,
        "**/node_modules": true,
        "**/.DS_Store": true,
        "**/dist": true
    },
    "C_Cpp.files.exclude": {
        "**/.vscode": true
    },
    "editor.accessibilitySupport": "off",
    "extensions.ignoreRecommendations": true,
    "workbench.startupEditor": "none",
    "explorer.confirmDelete": false,
    "output.smartScroll.enabled": false,
    "Codegeex.Comment.LanguagePreference": "中文",
    "Codegeex.Chat.LanguagePreference": "中文",
    "Codegeex.SidebarUI.LanguagePreference": "中文",
    "Codegeex.Explanation.LanguagePreference": "zh-CN",
    "security.workspace.trust.untrustedFiles": "open",
    "security.workspace.trust.startupPrompt": "never",
    "Codegeex.Privacy": true
}

settings.json - Mac

json
{
    "workbench.colorTheme": "One Dark Pro",
    "editor.detectIndentation": false,
    "editor.tabSize": 4,
    "editor.insertSpaces": true,
    "editor.renderControlCharacters": true,
    "editor.renderWhitespace": "selection",
    "editor.fontFamily": "Iosevka,JetBrains Mono,HONOR Sans Cn,Consolas,monospace",
    "terminal.integrated.fontFamily": "JetBrains Mono,monospace",
    "terminal.integrated.fontWeight": "normal",
    "editor.fontSize": 13.5,
    "terminal.integrated.fontSize": 11,
    "editor.fontLigatures": false,
    "editor.fontVariations": false,
    "editor.tokenColorCustomizations": {
        "textMateRules": [
            {
                "scope": "comment",
                "settings": {
                    "fontStyle": "italic"
                }
            }
        ]
    },
    "editor.rulers": [80],
    "editor.wordWrap": "wordWrapColumn",
    "editor.wordWrapColumn": 80,
    "files.autoGuessEncoding": true,
    "files.autoSave": "afterDelay",
    "files.autoSaveDelay": 1000,
    "editor.defaultFormatter": "xaver.clang-format",
    "editor.formatOnSave": true,
    "editor.formatOnSaveMode": "file",
    "editor.formatOnPaste": true,
    "files.trimTrailingWhitespace": true,
    "editor.minimap.enabled": true,
    "C_Cpp.default.cppStandard": "c++17",
    "C_Cpp.default.cStandard": "c17",
    "C_Cpp.formatting": "clangFormat",
    "[c]": {
        "editor.defaultFormatter": "xaver.clang-format"
    },
    "[python]": {
        "editor.formatOnType": true
    },
    "python.defaultInterpreterPath": "/usr/local/Caskroom/miniconda/base/bin/python",
    "python.condaPath": "/usr/local/Caskroom/miniconda/base/bin/conda",
    "code-runner.executorMap": {
        "c": "cd $dir && gcc -std=c17 -g -Wall -O3 $fileName -o ~/build/$fileNameWithoutExt_c && ~/build/$fileNameWithoutExt_c",
        "cpp": "cd $dir && g++ -std=c++17 -g -Wall -O3 $fileName -o ~/build/$fileNameWithoutExt_cpp && ~/build/$fileNameWithoutExt_cpp"
    },
    "code-runner.saveFileBeforeRun": true,
    "code-runner.fileDirectoryAsCwd": true,
    "code-runner.saveAllFilesBeforeRun": true,
    "code-runner.runInTerminal": true,
    "code-runner.clearPreviousOutput": true,
    "debug.terminal.clearBeforeReusing": true,
    "doxdocgen.file.copyrightTag": ["@copyright Copyright (c) {year}"],
    "doxdocgen.file.fileTemplate": "@file {name}",
    "doxdocgen.file.versionTag": "@version 1.0",
    "doxdocgen.generic.authorEmail": "[email protected]",
    "doxdocgen.generic.authorName": "huping",
    "doxdocgen.generic.authorTag": "@author {author} ({email})",
    "doxdocgen.generic.order": ["brief", "tparam", "param", "return"],
    "doxdocgen.generic.paramTemplate": "@param {param}",
    "doxdocgen.generic.returnTemplate": "@return {type}",
    "doxdocgen.generic.splitCasingSmartText": true,
    "doxdocgen.file.fileOrder": ["file", "brief", "version", "date", "author", "copyright"],
    "terminal.integrated.profiles.windows": {
        "PowerShell -NoProfile": {
            "source": "PowerShell",
            "args": ["-NoProfile", "-NoExit", "-Command", "chcp 65001"]
        }
    },
    "terminal.integrated.defaultProfile.windows": "PowerShell -NoProfile",
    "files.associations": {},
    "files.exclude": {
        "**/*.exe": true,
        "**/build": true,
        "**/.git": true,
        "**/node_modules": true,
        "**/.DS_Store": true,
        "**/dist": true
    },
    "C_Cpp.files.exclude": {
        "**/.vscode": true
    },
    "editor.accessibilitySupport": "off",
    "extensions.ignoreRecommendations": true,
    "workbench.startupEditor": "none",
    "explorer.confirmDelete": false,
    "output.smartScroll.enabled": false,
    "Codegeex.Comment.LanguagePreference": "中文",
    "Codegeex.Chat.LanguagePreference": "中文",
    "Codegeex.SidebarUI.LanguagePreference": "中文",
    "Codegeex.Explanation.LanguagePreference": "zh-CN",
    "security.workspace.trust.untrustedFiles": "open",
    "security.workspace.trust.startupPrompt": "never",
    "Codegeex.Privacy": true
}

c_cpp_properties.json - Mac

json
{
    "configurations": [
        {
            "name": "Mac",
            "includePath": ["${workspaceFolder}/**", "/usr/local/Cellar/gcc/14.1.0_2/lib/gcc/current/gcc/x86_64-apple-darwin21/14/include", "/usr/local/Cellar/gcc/14.1.0_2/lib/gcc/current/gcc/x86_64-apple-darwin21/14/finclude", "/usr/local/Cellar/gcc/14.1.0_2/lib/gcc/current/gcc/x86_64-apple-darwin21/14/include-fixed", "/usr/local/Cellar/gcc/14.1.0_2/include/c++/14", "/usr/local/Cellar/gcc/14.1.0_2/lib/gcc/current/gcc/x86_64-apple-darwin21/14", "/usr/local/Cellar/gcc/14.1.0_2"],
            "defines": [],
            "macFrameworkPath": [],
            "compilerPath": "/usr/local/Cellar/gcc/14.1.0_2/bin/gcc-14",
            "intelliSenseMode": "macos-gcc-x64",
            "cStandard": "c17",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}

task.json - Windows

json
{
  "tasks": [
    {
      "type": "cppbuild",
      "label": "C/C++: g++.exe 生成活动文件",
      "command": "D:\\Dev-Cpp\\MinGW64\\bin\\g++.exe",
      "args": [
        "-fdiagnostics-color=always",
        "-g",
        "${file}",
        "-o",
        "${fileDirname}\\${fileBasenameNoExtension}.exe"
      ],
      "options": {
        "cwd": "${fileDirname}"
      },
      "problemMatcher": ["$gcc"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "调试器生成的任务。"
    }
  ],
  "version": "2.0.0"
}

launch.json - Windows

json
{
    "configurations": [
        {
            "name": "C/C++: g++.exe 生成和调试活动文件",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\Dev-Cpp\\MinGW64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe 生成活动文件"
        }
    ],
    "version": "2.0.0"
}