Search code examples
powershellvisual-studio-coderefactoring

PowerShell rename refactor (F2) does nothing in VS Code


Pressing F2 when editing a PowerShell file does nothing in VS Code. (for other languages like C#, Python rename refactor (F2) works fine)

What I've tried:

  • completely uninstalled MS PowerShell extension and reinstalled it, including VS Code restarts
  • checked the Keyboard Shortcuts: PowerShell keybindings are present when PowerShell extension is installed, not present when uninstalled
  • Rename Symbol (editor.action.rename) is bind to F2 (and again, it works for other languages)
  • Edited file extension is .PS1, I can run and debug it, so VS Code recognizes (?) it a PowerShell file

Solution

  • This is not currently supported by VS Code's builtin PowerShell language support or the non-builtin PowerShell VS Code extension, but there is an open feature-request issue ticket for it: F2 (rename) doesn't work for PowerShell variables #1440, and also "Smart" variable rename #261. I suggest that you give those issue tickets a thumbs up to show support for it. You can also subscribe to them to get notified about discussion and progress. Please avoid making noisy comments there like ones that just consist of "+1" / "bump". If you're interested in helping implement the feature, there's related guidance here.