How do I find and replace all occurrences (in all files) in Visual Studio Code?

后端 未结 7 1923
轻奢々
轻奢々 2020-12-04 05:25

I can\'t figure out how to find and replace all occurrences of a word in different files using Visual Studio Code version 1.0.

I get the impression this should be po

相关标签:
7条回答
  • 2020-12-04 06:04

    This is the best way.

    1. First put your cursor on the member and click F2.

    2. Then type the new name and hit the Enter key. This will rename all of the occurrences in every file in your project.

    This is ideal for when you want to rename across multiple files. For example, you may want to rename a publicly accessible function on an Angular service and have everywhere that uses it get updated.

    For more great tools I highly recommend: https://johnpapa.net/refactoring-with-visual-studio-code/

    0 讨论(0)
  • 2020-12-04 06:05

    I'm using Visual Studio Code 1.8, and this feature is available. But it's a little tricky to understand at first, and (at the time of writing) the docs don't explain clearly how to use it, so here's how it works, step by step:

    Invoke Replace in Files (under the Edit menu, or with shortcut Ctrl+Shift+H)

    You'll see a standard Find/Replace input replacing the files pane on the left:

    Enter your search string and the replace string, then press enter. It may churn for a second searching all files, then it'll show the proposed changes in all your project files -- but note, these changes haven't been made yet! Here's what it looks like:

    Now you need to make the changes (and even after that, you have to save the modified files.)

    You can make those changes in various ways:

    1) Make all changes to all files at once.

    Click the replace icon next to your replace string (note: you'll get a dialog to confirm this bulk action.)

    2) Make all changes in a single file at once.

    Click the replace icon next to the filename (note: the icon only shows up when you hover over the filename row)

    3) Make a single change in a single file.

    Click the replace icon next to the individual change: (note: the icon only shows up when you hover over the change row)

    Finally, don't forget to save!

    All those files are now modified in the editor and not yet saved to disk.

    Use File -> Save All (or Ctrl+Alt+S)

    Update: I'm not sure when this was added, but if you click the "Replace all" button and see this dialog, clicking "Replace" will change and save all files in one click:

    0 讨论(0)
  • 2020-12-04 06:09

    On the Visual Studio Code Key Bindings page, the section Keyboard Shortcuts Reference has links to a PDF for each major OS. Once open, search for "replace in files" or any other shortcut you might need.

    Another way is to use the Command Palette (ctrl/cmd+shift+P) where you can type "replace" to list all related commands, including the one you want:

    Replace in Files ctrl/cmd+shift+H

    0 讨论(0)
  • 2020-12-04 06:10

    To replace a string in a single file (currently opened): CTRL + H

    For replacing at workspace level use: CTRL + SHIFT + H

    0 讨论(0)
  • 2020-12-04 06:12

    Update - as of version 1.3 (june 2016) it is possible to search and replace in Visual Studio Code. Using ctrl + shift + f , you can search and replace text in all files.


    It seems this is not possible at the moment (Version 1.1.1 (April 2016))

    "Q: Is it possible to globally search and replace?

    A: This feature is not yet implemented, but you can expect it to come in the future!"

    https://code.visualstudio.com/Docs/editor/codebasics

    This seems also requested by community: https://github.com/Microsoft/vscode/issues/1690

    0 讨论(0)
  • 2020-12-04 06:14

    There are 2 methods technically same

    1. First put your cursor on the word and press F2. Replace your word and press Enter.

    2. First put your cursor on the word and left click it. Click "Rename Symbol" option. Replace your word and press Enter.

    0 讨论(0)
提交回复
热议问题