VSCode设置和键盘快捷键

Published on
Published on
/5 mins read/---

从命令行启动 code

为了从命令行启动 code,你需要将 code 添加到你的 PATH 环境变量中。

打开VSCode的命令面板 (Cmd+Shift+P) 并输入 shell command 来打开Shell Command菜单:

Shell command

选择 Install 'code' command in PATH

如果你的系统出现权限被拒绝的错误,如下所示:

EACCES: permission denied
unlink '/usr/local/bin/code'

只需先运行 Unintall 'code' command in PATH,然后再次运行 Install 'code' command in PATH。这应该能解决问题。

现在尝试使用 code 命令打开文件或文件夹:

$ code ~/.bash_profile
# 或者 cd ./your-project && code .

项目/文件现在应该在VSCode中打开了。

VSCode设置

settings.json
{
  "editor.fontFamily": "JetBrains Mono, Monaco, 'Courier New', monospace",
  "prettier.useTabs": false,
  "editor.autoIndent": "full",
  "editor.tabSize": 2,
  "terminal.integrated.fontSize": 15,
  "editor.fontSize": 17,
  "git.autofetch": true,
  "javascript.updateImportsOnFileMove.enabled": "always",
  "editor.wordSeparators": "`~!@#%^&*()=+[{]}\\|;:'\",.<>/?",
  "editor.suggest.snippetsPreventQuickSuggestions": false,
  "redhat.telemetry.enabled": false,
  "mdx-preview.preview.useWhiteBackground": true,
  "scss.validate": false,
  "turboConsoleLog.logMessagePrefix": "👉 -------->",
  "turboConsoleLog.insertEnclosingClass": false,
  "turboConsoleLog.insertEnclosingFunction": false,
  "turboConsoleLog.delimiterInsideMessage": "-",
  "debug.console.fontSize": 16,
  "markdown.preview.fontSize": 16,
  "editor.defaultFormatter": "dbaeumer.vscode-eslint",
  "typescript.updateImportsOnFileMove.enabled": "always",
  "turboConsoleLog.includeFileNameAndLineNum": false,
  "editor.inlineSuggest.enabled": true,
  "editor.bracketPairColorization.enabled": true,
  "editor.guides.bracketPairsHorizontal": false,
  "[shellscript]": {
    "editor.defaultFormatter": "foxundermoon.shell-format"
  },
  "[prisma]": {
    "editor.defaultFormatter": "Prisma.prisma"
  },
  "[scss]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[json]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "editor.unicodeHighlight.allowedCharacters": {
    "️": true
  },
  "[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[typescriptreact]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "editor.detectIndentation": false,
  "editor.insertSpaces": true,
  "editor.quickSuggestions": {
    "strings": true
  },
  "turboConsoleLog.quote": "'",
  "git.suggestSmartCommit": false,
  "workbench.iconTheme": "material-icon-theme",
  "editor.fontLigatures": true,
  "workbench.fontAliasing": "auto",
  "editor.fontWeight": "normal",
  "git.inputValidationSubjectLength": 100,
  "git.inputValidationLength": 100,
  "diffEditor.ignoreTrimWhitespace": false,
  "tailwindCSS.classAttributes": [
    "class",
    "className",
    "ngClass",
    "headerClass",
    "triggerClass",
    "cls",
    "wrapperClass",
    "containerClassName",
    ".*ClassName",
    ".*Class"
  ],
  "tailwindCSS.experimental.classRegex": [
    ["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
    ["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
  ],
  "github.copilot.enable": {
    "*": false,
    "plaintext": true,
    "markdown": true,
    "scminput": false,
    "yaml": false
  },
  "files.associations": {
    "*.liquid": "liquid",
    "*.css": "tailwindcss"
  },
  "[liquid]": {
    "editor.formatOnSave": false,
    "editor.defaultFormatter": "Shopify.theme-check-vscode"
  },
  "files.autoSaveDelay": 100,
  "git.confirmSync": false,
  "tailwindCSS.includeLanguages": {
    "plaintext": "html"
  },
  "editor.formatOnSave": true,
  "[dotenv]": {
    "editor.defaultFormatter": "foxundermoon.shell-format"
  },
  "[svg]": {
    "editor.defaultFormatter": "jock.svg"
  },
  "workbench.preferredLightColorTheme": "Solarized Light",
  "[properties]": {
    "editor.defaultFormatter": "foxundermoon.shell-format"
  },
  "[ignore]": {
    "editor.defaultFormatter": "foxundermoon.shell-format"
  },
  "window.confirmBeforeClose": "keyboardOnly",
  "cSpell.userWords": [
    /*...*/
  ],
  "cSpell.enableFiletypes": ["schema.prisma"],
  "typescript.tsserver.log": "off",
  "window.autoDetectColorScheme": true,
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "workbench.colorTheme": "Solarized Light",
  "[tailwindcss]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "github.copilot.editor.enableAutoCompletions": false,
  "github.copilot.editor.enableCodeActions": false,
  "supermaven.otherWarning": false,
  "git.openRepositoryInParentFolders": "never",
  "[markdown]": {
    "editor.defaultFormatter": "yzhang.markdown-all-in-one"
  },
  "editor.codeActionsOnSave": {},
  "[mdx]": {
    "editor.defaultFormatter": "unifiedjs.vscode-mdx"
  },
  "[plaintext]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "security.workspace.trust.untrustedFiles": "open"
}

键盘快捷键:

keybindings.json
[
	{
		"key": "cmd+r",
		"command": "-workbench.action.reloadWindow",
		"when": "isDevelopment"
	},
	{
		"key": "cmd+k",
		"command": "workbench.action.terminal.clear",
		"when": "terminalFocus"
	},
	{
		"key": "ctrl+shift+r",
		"command": "-editor.action.refactor",
		"when": "editorHasCodeActionsProvider && editorTextFocus && !editorReadonly"
	},
	{
		"key": "cmd+r",
		"command": "editor.action.rename",
		"when": "editorHasRenameProvider && editorTextFocus && !editorReadonly"
	},
	{
		"key": "f2",
		"command": "-editor.action.rename",
		"when": "editorHasRenameProvider && editorTextFocus && !editorReadonly"
	},
	{
		"key": "shift+cmd+d",
		"command": "-workbench.view.debug",
		"when": "viewContainer.workbench.view.debug.enabled"
	},
	{
		"key": "shift+cmd+d",
		"command": "duplicate.execute"
	},
	{
		"key": "cmd+l",
		"command": "turboConsoleLog.displayLogMessage"
	},
	{
		"key": "ctrl+alt+l",
		"command": "-turboConsoleLog.displayLogMessage"
	},
	{
		"key": "cmd+j",
		"command": "-workbench.action.togglePanel"
	},
	{
		"key": "cmd+j",
		"command": "workbench.action.terminal.toggleTerminal",
		"when": "terminal.active"
	},
	{
		"key": "ctrl+`",
		"command": "-workbench.action.terminal.toggleTerminal",
		"when": "terminal.active"
	},
	{
		"key": "shift+cmd+l",
		"command": "turboConsoleLog.deleteAllLogMessages"
	},
	{
		"key": "shift+alt+d",
		"command": "-turboConsoleLog.deleteAllLogMessages"
	},
	{
		"key": "shift+cmd+g",
		"command": "workbench.view.scm",
		"when": "workbench.scm.active"
	},
	{
		"key": "ctrl+shift+g",
		"command": "-workbench.view.scm",
		"when": "workbench.scm.active"
	},
	{
		"key": "alt+p",
		"command": "git.push"
	},
	{
		"key": "shift+alt+p",
		"command": "git.pullFrom"
	},
	{
		"key": "cmd+u",
		"command": "references-view.findReferences",
		"when": "editorHasReferenceProvider"
	},
	{
		"key": "shift+alt+f12",
		"command": "-references-view.findReferences",
		"when": "editorHasReferenceProvider"
	},
	{
		"key": "cmd+u",
		"command": "-cursorUndo",
		"when": "textInputFocus"
	},
	{
		"key": "alt+tab",
		"command": "workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup",
		"when": "!activeEditorGroupEmpty"
	},
	{
		"key": "ctrl+tab",
		"command": "-workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup",
		"when": "!activeEditorGroupEmpty"
	},
	{
		"key": "alt+tab",
		"command": "workbench.action.quickOpenNavigateNextInEditorPicker",
		"when": "inEditorsPicker && inQuickOpen"
	},
	{
		"key": "ctrl+tab",
		"command": "-workbench.action.quickOpenNavigateNextInEditorPicker",
		"when": "inEditorsPicker && inQuickOpen"
	},
	{
		"key": "shift+alt+tab",
		"command": "workbench.action.quickOpenLeastRecentlyUsedEditorInGroup",
		"when": "!activeEditorGroupEmpty"
	},
	{
		"key": "ctrl+shift+tab",
		"command": "-workbench.action.quickOpenLeastRecentlyUsedEditorInGroup",
		"when": "!activeEditorGroupEmpty"
	},
	{
		"key": "shift+alt+tab",
		"command": "workbench.action.quickOpenNavigatePreviousInEditorPicker",
		"when": "inEditorsPicker && inQuickOpen"
	},
	{
		"key": "ctrl+shift+tab",
		"command": "-workbench.action.quickOpenNavigatePreviousInEditorPicker",
		"when": "inEditorsPicker && inQuickOpen"
	},
	{
		"key": "shift+cmd+,",
		"command": "workbench.action.openSettings"
	},
	{
		"key": "cmd+,",
		"command": "-workbench.action.openSettings"
	},
	{
		"key": "cmd+q",
		"command": "-workbench.action.quit"
	},
	{
		"key": "cmd+o",
		"command": "-workbench.action.files.openFile",
		"when": "false"
	},
	{
		"key": "cmd+o",
		"command": "-workbench.action.files.openFolderViaWorkspace",
		"when": "!openFolderWorkspaceSupport && workbenchState == 'workspace'"
	},
	{
		"key": "cmd+o",
		"command": "-workbench.action.files.openFileFolder",
		"when": "isMacNative && openFolderWorkspaceSupport"
	},
	{
		"key": "cmd+o",
		"command": "-workbench.action.files.openLocalFileFolder",
		"when": "remoteFileDialogVisible"
	}
]

主要键盘快捷键说明:

  • Cmd+R: 重命名符号(替代默认的F2)
  • Cmd+K: 清空终端(当终端聚焦时)
  • Shift+Cmd+D: 复制行
  • Cmd+L: 插入console.log(Turbo Console Log插件)
  • Shift+Cmd+L: 删除所有console.log
  • Cmd+J: 切换终端显示
  • Shift+Cmd+G: 打开源代码管理视图
  • Alt+P: Git推送
  • Shift+Alt+P: Git拉取
  • Cmd+U: 查找引用
  • Alt+Tab: 在最近使用的编辑器间切换
  • Shift+Cmd+,: 打开设置

Happy coding!