乐闻世界logo
搜索文章和话题

What are the VS Code terminal integration features?

2月18日 18:15

VS Code has built-in powerful terminal integration features, allowing direct use of command line tools within the editor without switching windows, greatly improving development efficiency.

Terminal Basics

Opening Terminal

  • Shortcut: Ctrl+` (backtick)
  • Menu: View > Terminal
  • Command Palette: Terminal: Create New Terminal

Multi-terminal Management

  • Create new terminal: + button in top-right of terminal panel
  • Switch terminals: Click terminal tabs or use shortcuts
  • Split terminal: Split button in top-right of terminal panel

Terminal Configuration

Terminal Type Configuration

json
{ "terminal.integrated.defaultProfile.windows": "PowerShell", "terminal.integrated.defaultProfile.osx": "zsh", "terminal.integrated.defaultProfile.linux": "bash" }

Terminal Appearance Configuration

json
{ "terminal.integrated.fontSize": 13, "terminal.integrated.fontFamily": "Menlo, Monaco, 'Courier New'", "terminal.integrated.lineHeight": 1.2, "terminal.integrated.cursorBlinking": true, "terminal.integrated.cursorStyle": "block" }

Terminal Color Configuration

json
{ "workbench.colorCustomizations": { "terminal.ansiBlack": "#000000", "terminal.ansiRed": "#cd3131", "terminal.ansiGreen": "#0dbc79", "terminal.ansiYellow": "#e5e510", "terminal.ansiBlue": "#2472c8", "terminal.ansiMagenta": "#bc3fbc", "terminal.ansiCyan": "#11a8cd", "terminal.ansiWhite": "#e5e5e5" } }

Terminal Operations

Common Shortcuts

  • Ctrl+`: Toggle terminal visibility
  • Ctrl+Shift+`: Create new terminal
  • Ctrl+1/2/3...: Switch to specific terminal
  • Ctrl+Shift+1/2/3...: Focus on specific terminal
  • Ctrl+C: Terminate current command
  • Ctrl+Shift+C: Copy terminal content
  • Ctrl+Shift+V: Paste to terminal

Terminal Command History

  • Up/Down Arrow: Browse command history
  • Ctrl+R: Search command history
  • Ctrl+G: Exit search mode

Terminal Scrolling

  • Shift+PageUp/PageDown: Fast scrolling
  • Ctrl+Home/End: Jump to start/end

Terminal Integration Features

Opening Files from Terminal

bash
# Execute in terminal code filename.js code .

Selecting Text from Terminal

  • Use mouse to select text
  • Automatically copy to clipboard
  • Support multi-line selection
  • File paths in terminal are clickable
  • Automatically open corresponding files
  • Support line number jumping

Task Integration

Running Commands from Tasks

json
{ "version": "2.0.0", "tasks": [ { "label": "Run Tests", "type": "shell", "command": "npm test", "presentation": { "reveal": "always", "panel": "new" } } ] }

Task Configuration Options

  • reveal: When to show terminal (always, silent, never)
  • panel: Which terminal to use (shared, new, dedicated)
  • focus: Whether to focus terminal
  • clear: Whether to clear terminal content

Terminal Environment

Environment Variable Configuration

json
{ "terminal.integrated.env.windows": { "PATH": "${env:PATH};C:\\myapp\\bin" }, "terminal.integrated.env.osx": { "PATH": "${env:PATH}:/usr/local/myapp/bin" } }

Working Directory Configuration

json
{ "terminal.integrated.cwd": "${workspaceFolder}" }

Advanced Features

Terminal Shell Integration

  • Automatically detect Shell type
  • Support custom Shell scripts
  • Provide intelligent prompts

Terminal Profiles

Create custom terminal configuration:

json
{ "terminal.integrated.profiles.windows": { "PowerShell": { "source": "PowerShell", "icon": "terminal-powershell" }, "Git Bash": { "path": "C:\\Program Files\\Git\\bin\\bash.exe", "args": ["--login"] } } }

Terminal API

Operate terminal in extensions:

typescript
const terminal = vscode.window.createTerminal('My Terminal'); terminal.sendText('echo Hello World'); terminal.show();

Common Shell Configurations

PowerShell

json
{ "terminal.integrated.defaultProfile.windows": "PowerShell", "powershell.integrated.consoleTitleTemplate": "PowerShell: ${cwd}" }

Git Bash

json
{ "terminal.integrated.profiles.windows": { "Git Bash": { "path": "C:\\Program Files\\Git\\bin\\bash.exe", "args": ["--login", "-i"] } } }

WSL

json
{ "terminal.integrated.profiles.windows": { "WSL": { "path": "wsl.exe", "args": ["-d", "Ubuntu"] } } }

Important Notes

  • Terminal sessions end when VS Code closes
  • Long-running commands may affect performance
  • Pay attention to terminal command security
  • Use terminal history wisely
  • Consider using terminal extensions for enhanced functionality
标签:VSCode