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

What are the advanced uses of VS Code search features?

2月18日 18:17

VS Code provides powerful search and find features, supporting in-file, cross-file, regex and other search methods, helping quickly locate code and content.

Find in File

  • Shortcut: Ctrl+F
  • Function: Find text in currently open file
  • Features: Support case sensitivity, whole word match, regex

Replace in File

  • Shortcut: Ctrl+H
  • Function: Find and replace text in current file
  • Operation: Enter replacement content after finding, select replacement scope

Find in Workspace

  • Shortcut: Ctrl+Shift+F
  • Function: Search text across entire workspace
  • Location: Sidebar search view

Replace in Workspace

  • Shortcut: Ctrl+Shift+H
  • Function: Find and replace across entire workspace
  • Features: Support previewing replacement results

Basic Options

  • Case Sensitive: Aa icon button
  • Match Whole Word: Ab icon button
  • Use Regular Expression: .* icon button
  • Use Exclude Files: Exclude specific files when searching

Advanced Options

  • Include: Specify file patterns to search
  • Exclude: Specify file patterns to exclude
  • Context Lines: Show context of matches

Regex Syntax

javascript
// Find function calls function\s+(\w+)\s*\(([^)]*)\) // Find email addresses [\w.]+@[\w.]+\.\w+ // Find URLs https?:\/\/[^\s]+

Using Capture Groups

javascript
// Find and replace // Find: (\w+)\.(\w+)\((.*)\) // Replace: $2($1, $3)
  • Search results displayed in search panel
  • Click results to jump to corresponding location
  • Support keyboard navigation
  • F3/Shift+F3: Next/previous match
  • Enter: Open selected result
  • Ctrl+Enter: Open in new editor

Configure in settings.json:

json
{ "search.exclude": { "**/node_modules": true, "**/dist": true, "**/.git": true, "**/*.min.js": true } }
json
{ "search.include": { "**/*.js": true, "**/*.ts": true, "**/*.jsx": true } }

Using .gitignore

json
{ "search.useIgnoreFiles": true, "search.useParentIgnoreFiles": true }
  • Shortcut: Ctrl+T
  • Function: Search symbols in workspace (functions, classes, variables, etc.)
  • Features: Support fuzzy matching
  • Shortcut: Ctrl+P
  • Function: Quick open files
  • Features: Support fuzzy matching and symbol jumping
  • Shortcut: Ctrl+Shift+O
  • Function: Search symbols in current file
  • Features: Grouped display by type

Common Shortcuts

  • Ctrl+F: Find in file
  • Ctrl+H: Replace in file
  • Ctrl+Shift+F: Find in workspace
  • Ctrl+Shift+H: Replace in workspace
  • Ctrl+T: Symbol search
  • Ctrl+P: File search
  • F3: Next match
  • Shift+F3: Previous match
  • Use partial name search
  • Support camelCase matching
  • Automatically ignore case
javascript
// Search multiple keywords keyword1 OR keyword2 // Exclude specific content keyword -exclude
  • Set context lines to view more information
  • Use "Open in context" to view complete code

Performance Optimization

  • Reasonably configure exclusion rules
  • Use file type filtering
  • Limit search scope
  • VS Code automatically caches search results
  • Support incremental search
  • Reduce duplicate search time

Important Notes

  • Regex search may affect performance
  • Large projects recommended to use exclusion rules
  • Search results can be saved and exported
  • Support search history
  • Pay attention to search result accuracy
标签:VSCode