VSCode設定ガイド:プロレベルの開発効率を実現するカスタマイズ完全版

VSCode設定ガイド:プロレベルの開発効率を実現するカスタマイズ完全版

Visual Studio Code(VSCode)は、軽量でありながら強力な機能を持つ無料のコードエディタです。適切な設定とカスタマイズにより、プロフェッショナルな開発環境を構築できます。この記事では、初心者から上級者まで役立つ、VSCodeの包括的な設定ガイドを提供します。

VSCodeの魅力と選ばれる理由

なぜVSCodeが人気なのか

VSCodeが多くの開発者に選ばれる理由:

  • 軽量性: 高速な起動と軽快な動作
  • 拡張性: 豊富な拡張機能エコシステム
  • 統合機能: Git、ターミナル、デバッガーの統合
  • 言語サポート: 多言語対応とIntelliSense
  • 無料: 完全無料でオープンソース
  • クロスプラットフォーム: Windows、Mac、Linux対応

開発者統計データ

Stack Overflow Developer Survey 2023:
┌─────────────────────┬──────────┐
│ エディタ/IDE         │ 使用率   │
├─────────────────────┼──────────┤
│ Visual Studio Code  │ 73.7%    │
│ Notepad++           │ 32.6%    │
│ Vim                 │ 22.2%    │
│ IntelliJ            │ 20.3%    │
│ Android Studio      │ 11.4%    │
└─────────────────────┴──────────┘

基本設定の最適化

settings.jsonの基本設定

VSCodeの設定はsettings.jsonファイルで管理されます。以下が推奨設定です:

{
  // ============= エディタ基本設定 =============
  "editor.fontSize": 14,
  "editor.fontFamily": "'Fira Code', 'JetBrains Mono', 'Cascadia Code', Consolas, 'Courier New', monospace",
  "editor.fontLigatures": true,
  "editor.lineHeight": 1.5,
  "editor.tabSize": 2,
  "editor.insertSpaces": true,
  "editor.detectIndentation": true,
  "editor.wordWrap": "on",
  "editor.wordWrapColumn": 120,
  "editor.rulers": [80, 120],

  // ============= 表示設定 =============
  "editor.minimap.enabled": true,
  "editor.minimap.maxColumn": 120,
  "editor.minimap.renderCharacters": false,
  "editor.cursorBlinking": "smooth",
  "editor.cursorSmoothCaretAnimation": "on",
  "editor.smoothScrolling": true,
  "editor.renderWhitespace": "boundary",
  "editor.renderLineHighlight": "all",
  "editor.lineNumbers": "on",
  "editor.folding": true,
  "editor.showFoldingControls": "mouseover",

  // ============= 自動保存・フォーマット =============
  "files.autoSave": "afterDelay",
  "files.autoSaveDelay": 1000,
  "editor.formatOnSave": true,
  "editor.formatOnPaste": true,
  "editor.formatOnType": false,
  "editor.codeActionsOnSave": {
    "source.organizeImports": true,
    "source.fixAll": true,
    "source.fixAll.eslint": true
  },

  // ============= ファイル設定 =============
  "files.trimTrailingWhitespace": true,
  "files.insertFinalNewline": true,
  "files.trimFinalNewlines": true,
  "files.encoding": "utf8",
  "files.eol": "n",

  // ============= エクスプローラー設定 =============
  "explorer.confirmDelete": false,
  "explorer.confirmDragAndDrop": false,
  "explorer.compactFolders": false,
  "explorer.sortOrder": "type",

  // ============= 検索設定 =============
  "search.exclude": {
    "**/node_modules": true,
    "**/bower_components": true,
    "**/*.code-search": true,
    "**/dist": true,
    "**/build": true,
    "**/.git": true,
    "**/.DS_Store": true,
    "**/Thumbs.db": true
  },
  "files.watcherExclude": {
    "**/.git/objects/**": true,
    "**/.git/subtree-cache/**": true,
    "**/node_modules/*/**": true,
    "**/.hg/store/**": true
  },

  // ============= ターミナル設定 =============
  "terminal.integrated.fontSize": 13,
  "terminal.integrated.fontFamily": "'Fira Code', 'JetBrains Mono', monospace",
  "terminal.integrated.cursorBlinking": true,
  "terminal.integrated.cursorStyle": "line",
  "terminal.integrated.copyOnSelection": true,
  "terminal.integrated.rightClickBehavior": "paste",

  // ============= Git設定 =============
  "git.autofetch": true,
  "git.confirmSync": false,
  "git.enableSmartCommit": true,
  "git.postCommitCommand": "none",

  // ============= ワークベンチ設定 =============
  "workbench.colorTheme": "One Dark Pro",
  "workbench.iconTheme": "material-icon-theme",
  "workbench.editor.enablePreview": false,
  "workbench.editor.limit.enabled": true,
  "workbench.editor.limit.value": 8,
  "workbench.startupEditor": "newUntitledFile",

  // ============= Zen Mode設定 =============
  "zenMode.centerLayout": false,
  "zenMode.hideLineNumbers": false,
  "zenMode.hideStatusBar": false,
  "zenMode.hideTabs": false,

  // ============= その他の設定 =============
  "telemetry.telemetryLevel": "off",
  "update.mode": "manual",
  "extensions.autoUpdate": false,
  "breadcrumbs.enabled": true,
  "outline.showProperties": false
}

設定の階層と優先順位

VSCodeの設定には階層があります:

設定の優先順位(高→低):
1. ワークスペース設定 (.vscode/settings.json)
2. フォルダ設定 (.vscode/settings.json in multi-root)
3. ユーザー設定 (グローバル settings.json)
4. デフォルト設定

必須拡張機能とその設定

カテゴリ別拡張機能

🎨 テーマ・外観

{
  // 推奨テーマ拡張機能
  "extensions.recommendations": [
    "zhuangtongfa.Material-theme",
    "PKief.material-icon-theme",
    "oderwat.indent-rainbow",
    "CoenraadS.bracket-pair-colorizer-2"
  ]
}

主要テーマの特徴

テーマ名 特徴 適用場面
One Dark Pro 目に優しいダーク 長時間作業
Material Theme モダンなデザイン デザイン重視
Dracula 高コントラスト 集中作業
Nord ミニマル シンプル好み
Tokyo Night 落ち着いた色合い 夜間作業

⚡ 生産性向上

{
  // 生産性拡張機能の設定
  "auto-rename-tag.activationOnLanguage": [
    "html", "xml", "php", "javascript", "typescript", "jsx", "tsx"
  ],

  "bracket-pair-colorizer-2.colors": [
    "#ffd700", "#da70d6", "#87ceeb", "#fa8072", "#40e0d0", "#98fb98"
  ],

  "path-intellisense.mappings": {
    "@": "${workspaceRoot}/src",
    "~": "${workspaceRoot}"
  }
}

必須生産性拡張機能

# インストールコマンド(Extensions view で検索・インストール)
- Auto Rename Tag         # HTMLタグの自動リネーム
- Bracket Pair Colorizer 2 # 括弧のカラーマッチング
- Path Intellisense        # パス補完
- Auto Import              # 自動インポート
- Better Comments          # コメント強化
- TODO Highlight           # TODOハイライト
- Live Server              # ローカルサーバー
- Thunder Client           # API テスト
- GitLens                  # Git 強化
- Code Spell Checker       # スペルチェック

🔧 コード品質

{
  // コード品質設定
  "eslint.workingDirectories": ["./"],
  "eslint.format.enable": true,
  "eslint.codeAction.showDocumentation": {
    "enable": true
  },

  "prettier.requireConfig": true,
  "prettier.useEditorConfig": false,
  "prettier.tabWidth": 2,
  "prettier.semi": true,
  "prettier.singleQuote": true,
  "prettier.trailingComma": "es5",

  "sonarlint.rules": {
    "javascript:S1192": "off",
    "typescript:S1192": "off"
  }
}

言語別拡張機能

🐍 Python開発

{
  // Python設定
  "python.defaultInterpreterPath": "/usr/bin/python3",
  "python.linting.enabled": true,
  "python.linting.pylintEnabled": false,
  "python.linting.flake8Enabled": true,
  "python.linting.mypyEnabled": true,
  "python.formatting.provider": "black",
  "python.formatting.blackArgs": ["--line-length=88"],
  "python.sortImports.args": ["--profile", "black"],
  "python.testing.pytestEnabled": true,
  "python.testing.unittestEnabled": false,
  "python.testing.pytestArgs": ["."],

  // Jupyter設定
  "jupyter.askForKernelRestart": false,
  "jupyter.sendSelectionToInteractiveWindow": true,
  "jupyter.interactiveWindowMode": "perFile"
}

Python拡張機能パック

  • Python(Microsoft公式)
  • Pylance(高速言語サーバー)
  • Python Docstring Generator
  • autoDocstring
  • Jupyter
  • Python Test Explorer

🌐 Web開発

{
  // TypeScript/JavaScript設定
  "typescript.updateImportsOnFileMove.enabled": "always",
  "typescript.suggest.autoImports": true,
  "typescript.preferences.importModuleSpecifier": "relative",

  "javascript.updateImportsOnFileMove.enabled": "always",
  "javascript.suggest.autoImports": true,

  // HTML/CSS設定
  "html.format.indentInnerHtml": true,
  "html.format.wrapAttributes": "force-aligned",
  "css.validate": true,
  "scss.validate": true,
  "less.validate": true,

  // Emmet設定
  "emmet.includeLanguages": {
    "javascript": "javascriptreact",
    "typescript": "typescriptreact",
    "vue-html": "html"
  },
  "emmet.triggerExpansionOnTab": true
}

Web開発拡張機能

  • ES7+ React/Redux/React-Native snippets
  • HTML CSS Support
  • CSS Peek
  • Live Sass Compiler
  • REST Client
  • Debugger for Chrome
  • Vetur(Vue.js)
  • Angular Language Service

🗄️ データベース・その他

{
  // データベース設定
  "sqltools.connections": [
    {
      "name": "Local PostgreSQL",
      "driver": "PostgreSQL",
      "server": "localhost",
      "port": 5432,
      "database": "myapp",
      "username": "postgres"
    }
  ],

  // Docker設定
  "docker.showStartPage": false,
  "docker.truncateLongRegistryPaths": true,
  "docker.truncateMaxLength": 20
}

カスタムキーバインド設定

keybindings.jsonの最適化

効率的なキーバインド設定:

[
  // ============= エディタ操作 =============
  {
    "key": "ctrl+d",
    "command": "editor.action.deleteLines",
    "when": "editorTextFocus && !editorReadonly"
  },
  {
    "key": "ctrl+shift+d",
    "command": "editor.action.duplicateSelection",
    "when": "editorTextFocus"
  },
  {
    "key": "alt+up",
    "command": "editor.action.moveLinesUpAction",
    "when": "editorTextFocus && !editorReadonly"
  },
  {
    "key": "alt+down",
    "command": "editor.action.moveLinesDownAction",
    "when": "editorTextFocus && !editorReadonly"
  },
  {
    "key": "ctrl+shift+l",
    "command": "editor.action.selectHighlights",
    "when": "editorFocus"
  },

  // ============= ファイル・フォルダ操作 =============
  {
    "key": "ctrl+shift+e",
    "command": "workbench.view.explorer"
  },
  {
    "key": "ctrl+shift+f",
    "command": "workbench.view.search"
  },
  {
    "key": "ctrl+shift+g",
    "command": "workbench.view.scm"
  },
  {
    "key": "ctrl+shift+x",
    "command": "workbench.view.extensions"
  },

  // ============= ターミナル操作 =============
  {
    "key": "ctrl+`",
    "command": "workbench.action.terminal.toggleTerminal"
  },
  {
    "key": "ctrl+shift+`",
    "command": "workbench.action.terminal.new"
  },
  {
    "key": "ctrl+shift+c",
    "command": "workbench.action.terminal.openNativeConsole",
    "when": "!terminalFocus"
  },

  // ============= ナビゲーション =============
  {
    "key": "ctrl+p",
    "command": "workbench.action.quickOpen"
  },
  {
    "key": "ctrl+shift+p",
    "command": "workbench.action.showCommands"
  },
  {
    "key": "ctrl+t",
    "command": "workbench.action.showAllSymbols"
  },
  {
    "key": "ctrl+g",
    "command": "workbench.action.gotoLine"
  },

  // ============= マルチカーソル =============
  {
    "key": "ctrl+alt+up",
    "command": "editor.action.insertCursorAbove"
  },
  {
    "key": "ctrl+alt+down",
    "command": "editor.action.insertCursorBelow"
  },

  // ============= コード操作 =============
  {
    "key": "shift+alt+f",
    "command": "editor.action.formatDocument"
  },
  {
    "key": "ctrl+k ctrl+f",
    "command": "editor.action.formatSelection"
  },
  {
    "key": "f12",
    "command": "editor.action.revealDefinition"
  },
  {
    "key": "alt+f12",
    "command": "editor.action.peekDefinition"
  },

  // ============= Git操作 =============
  {
    "key": "ctrl+shift+g g",
    "command": "git.openChange"
  },
  {
    "key": "ctrl+shift+g s",
    "command": "git.stage"
  },
  {
    "key": "ctrl+shift+g u",
    "command": "git.unstage"
  },
  {
    "key": "ctrl+shift+g c",
    "command": "git.commitStaged"
  }
]

カスタムスニペット

JavaScript/TypeScript スニペット

{
  // ~/.vscode/snippets/javascript.json
  "Console Log": {
    "prefix": "clg",
    "body": [
      "console.log('${1:message}:', $2);"
    ],
    "description": "Console log with message"
  },

  "Arrow Function": {
    "prefix": "af",
    "body": [
      "const ${1:functionName} = (${2:params}) => {",
      "  ${3:// body}",
      "};"
    ],
    "description": "Arrow function"
  },

  "Try Catch": {
    "prefix": "tryc",
    "body": [
      "try {",
      "  ${1:// code}",
      "} catch (${2:error}) {",
      "  console.error('${3:Error}:', $2);",
      "  ${4:// error handling}",
      "}"
    ],
    "description": "Try catch block"
  },

  "Async Function": {
    "prefix": "asf",
    "body": [
      "const ${1:functionName} = async (${2:params}) => {",
      "  try {",
      "    ${3:// async code}",
      "  } catch (error) {",
      "    console.error('Error in ${1:functionName}:', error);",
      "    throw error;",
      "  }",
      "};"
    ],
    "description": "Async arrow function with error handling"
  }
}

Python スニペット

{
  // ~/.vscode/snippets/python.json
  "Print Debug": {
    "prefix": "pd",
    "body": [
      "print(f'${1:variable}: {${1:variable}}')"
    ],
    "description": "Print debug statement"
  },

  "Class Definition": {
    "prefix": "class",
    "body": [
      "class ${1:ClassName}:",
      "    """${2:Class description}"""",
      "    ",
      "    def __init__(self${3:, args}):",
      "        """Initialize ${1:ClassName}"""",
      "        ${4:pass}",
      "    ",
      "    def ${5:method_name}(self${6:, args}):",
      "        """${7:Method description}"""",
      "        ${8:pass}"
    ],
    "description": "Class definition with docstrings"
  },

  "Function with Docstring": {
    "prefix": "def",
    "body": [
      "def ${1:function_name}(${2:args}) -> ${3:return_type}:",
      "    """${4:Function description}",
      "    ",
      "    Args:",
      "        ${5:arg}: ${6:description}",
      "    ",
      "    Returns:",
      "        ${7:description}",
      "    """",
      "    ${8:pass}"
    ],
    "description": "Function with Google-style docstring"
  }
}

ワークスペース設定

.vscode/settings.json(プロジェクト設定)

プロジェクト固有の設定:

{
  // ============= プロジェクト固有設定 =============
  "python.defaultInterpreterPath": "./venv/bin/python",
  "python.terminal.activateEnvironment": true,

  // ============= ESLint設定 =============
  "eslint.workingDirectories": ["./frontend", "./backend"],
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact"
  ],

  // ============= 除外設定 =============
  "files.exclude": {
    "**/.git": true,
    "**/.DS_Store": true,
    "**/node_modules": true,
    "**/__pycache__": true,
    "**/*.pyc": true,
    "**/dist": true,
    "**/build": true
  },

  // ============= タスク固有設定 =============
  "typescript.preferences.importModuleSpecifier": "relative",
  "emmet.includeLanguages": {
    "javascript": "javascriptreact"
  }
}

launch.json(デバッグ設定)

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "envFile": "${workspaceFolder}/.env"
    },
    {
      "name": "Python: FastAPI",
      "type": "python",
      "request": "launch",
      "module": "uvicorn",
      "args": ["main:app", "--reload"],
      "envFile": "${workspaceFolder}/.env"
    },
    {
      "name": "Node.js: Current File",
      "type": "node",
      "request": "launch",
      "program": "${file}",
      "skipFiles": ["<node_internals>/**"]
    },
    {
      "name": "Chrome: Launch",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:3000",
      "webRoot": "${workspaceFolder}/src"
    }
  ]
}

tasks.json(タスク設定)

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Python: Run Tests",
      "type": "shell",
      "command": "python",
      "args": ["-m", "pytest", "-v"],
      "group": "test",
      "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "shared"
      }
    },
    {
      "label": "Python: Black Format",
      "type": "shell",
      "command": "black",
      "args": ["."],
      "group": "build",
      "presentation": {
        "echo": true,
        "reveal": "silent",
        "focus": false
      }
    },
    {
      "label": "npm: Install",
      "type": "npm",
      "script": "install",
      "group": "build"
    },
    {
      "label": "npm: Start Dev Server",
      "type": "npm",
      "script": "dev",
      "group": "build",
      "isBackground": true,
      "presentation": {
        "reveal": "always",
        "panel": "new"
      }
    }
  ]
}

パフォーマンス最適化

メモリ使用量の削減

{
  // ============= パフォーマンス設定 =============
  "extensions.autoUpdate": false,
  "extensions.autoCheckUpdates": false,

  "typescript.disableAutomaticTypeAcquisition": true,
  "typescript.surveys.enabled": false,

  "files.watcherExclude": {
    "**/.git/objects/**": true,
    "**/.git/subtree-cache/**": true,
    "**/node_modules/*/**": true,
    "**/.hg/store/**": true,
    "**/dist/**": true,
    "**/build/**": true
  },

  "search.followSymlinks": false,
  "search.smartCase": true,

  // ============= 大きなファイル対応 =============
  "editor.largeFileOptimizations": true,
  "diffEditor.maxComputationTime": 5000,

  // ============= UI最適化 =============
  "workbench.editor.limit.enabled": true,
  "workbench.editor.limit.value": 10,
  "workbench.editor.closeOnFileDelete": true,

  "editor.minimap.maxColumn": 80,
  "editor.minimap.renderCharacters": false,

  // ============= 言語サーバー最適化 =============
  "python.analysis.autoImportCompletions": false,
  "python.analysis.memory.keepLibraryAst": false
}

CPU使用率の最適化

# VSCodeのプロセス監視
# ターミナルで実行
top -p $(pgrep -f "code")

# 詳細なメモリ使用量確認
ps aux | grep -i code | head -10

トラブルシューティング

よくある問題と解決法

1. VSCodeの動作が重い

{
  // 軽量化設定
  "workbench.iconTheme": null,
  "editor.minimap.enabled": false,
  "editor.cursorSmoothCaretAnimation": "off",
  "editor.smoothScrolling": false,
  "workbench.reduceMotion": "on",
  "extensions.autoUpdate": false
}

2. 拡張機能のコンフリクト

# 拡張機能を無効化して起動
code --disable-extensions

# 特定の拡張機能のみ有効化
code --enable-proposed-api ms-python.python

3. 設定の同期問題

{
  // 設定同期の設定
  "settingsSync.ignoredExtensions": [
    "ms-vscode.vscode-typescript-next"
  ],
  "settingsSync.ignoredSettings": [
    "python.defaultInterpreterPath"
  ]
}

4. ファイル監視エラー

# Linux/Macでファイル監視制限を増加
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

ログとデバッグ

開発者ツールの使用

// VSCode開発者ツール(Ctrl+Shift+I)
// コンソールで実行可能なコマンド

// ワークスペース情報
console.log(vscode.workspace.workspaceFolders);

// アクティブエディタ情報
console.log(vscode.window.activeTextEditor);

// 拡張機能リスト
vscode.extensions.all.forEach(ext => {
  console.log(`${ext.id}: ${ext.isActive}`);
});

ログファイルの確認

# Windows
%APPDATA%Codelogs

# macOS
~/Library/Application Support/Code/logs/

# Linux
~/.config/Code/logs/

高度なカスタマイズ

カスタムCSS(非公式)

/* カスタムCSS例(Custom CSS and JS Loader拡張機能使用) */
.monaco-editor .current-line {
  border: 1px solid #3e4451 !important;
}

.monaco-workbench .part.editor>.content .editor-group-container {
  background: linear-gradient(45deg, #1e1e1e, #252526) !important;
}

.tabs-and-actions-container .tab {
  border-radius: 5px 5px 0 0 !important;
  margin-right: 2px !important;
}

拡張機能の開発

基本的な拡張機能構造

{
  "name": "my-extension",
  "version": "1.0.0",
  "engines": {
    "vscode": "^1.74.0"
  },
  "categories": ["Other"],
  "activationEvents": [
    "onCommand:extension.sayHello"
  ],
  "main": "./extension.js",
  "contributes": {
    "commands": [
      {
        "command": "extension.sayHello",
        "title": "Hello World"
      }
    ]
  }
}

チーム開発での設定共有

.vscode フォルダの管理

# .gitignore内でのVSCode設定管理
.vscode/
!.vscode/settings.json
!.vscode/launch.json
!.vscode/tasks.json
!.vscode/extensions.json

推奨拡張機能の共有

{
  // .vscode/extensions.json
  "recommendations": [
    "ms-python.python",
    "ms-python.pylance",
    "esbenp.prettier-vscode",
    "dbaeumer.vscode-eslint",
    "bradlc.vscode-tailwindcss",
    "ms-vscode.vscode-typescript-next"
  ],
  "unwantedRecommendations": [
    "ms-vscode.vscode-typescript"
  ]
}

設定のテンプレート化

# プロジェクトテンプレート作成スクリプト
#!/bin/bash

PROJECT_NAME=$1
mkdir -p $PROJECT_NAME/.vscode

# 基本設定をコピー
cp templates/vscode-settings.json $PROJECT_NAME/.vscode/settings.json
cp templates/vscode-launch.json $PROJECT_NAME/.vscode/launch.json
cp templates/vscode-tasks.json $PROJECT_NAME/.vscode/tasks.json
cp templates/vscode-extensions.json $PROJECT_NAME/.vscode/extensions.json

echo "VSCode設定を$PROJECT_NAMEにセットアップしました"

まとめ

VSCodeの適切な設定とカスタマイズにより、開発効率を大幅に向上させることができます。この記事で紹介した設定を参考に、自分の開発スタイルに最適な環境を構築しましょう。

重要なポイント

  1. 段階的導入: 一度にすべての設定を変更せず、段階的に試す
  2. チーム標準化: チーム開発では設定の共有と標準化が重要
  3. 継続的改善: 新機能や拡張機能を定期的に評価・導入
  4. パフォーマンス重視: 機能性と軽快さのバランスを保つ
  5. バックアップ: 設定のバックアップと同期を適切に管理

次のステップ

VSCodeをマスターしたら、以下の分野についてさらに学習することをお勧めします:

  • カスタム拡張機能の開発
  • デバッグ技術の向上
  • リモート開発(SSH、Container、WSL)
  • 協業ツールとの連携
  • AIアシスト機能の活用

VSCodeは継続的に進化しているエディタです。最新の機能やベストプラクティスを常に学習し、自分の開発ワークフローを最適化し続けましょう。

ご質問やご意見がありましたら、お問い合わせページからお気軽にご連絡ください!


関連記事:

コメントする