How can I refactor file names in Visual Studio Code?

12,010

Solution 1

Actually you can. Natively on Visual Studio Code (>= v1.28) with import path renaming:

Renaming JavaScript import path in VS Code

Or with some extension like Move TS.

Solution 2

Sorry, but the answer is just simple: No, you can't.

At least not currently. It's up to the authors of the language modes to implement such things. There is support for the occasional variable refactoring here and there… And there are some additional extensions in the JavaScript space that support method extraction and stuff, but none of them handles filename refactoring.

Share:
12,010
Oleg Korol
Author by

Oleg Korol

BY DAY: I work as a Web Developer (full-stack, more focused on backend) at Interone GmbH in Munich, Germany. BY NIGHT: I like to code my own projects using JavaScript. Current stack: Angular, Vue, Koa, Express, MongoDB, MySQL, etc.

Updated on June 03, 2022

Comments

  • Oleg Korol
    Oleg Korol almost 2 years

    Is it possible to refactor the name of the files in a project and automatically update all the imports, without caring about breaking something each time a file name is changed?

    In the same manner as in the JetBrains' products. You change the file name and everything is automatically updated.

  • Oleg Korol
    Oleg Korol over 5 years
    I saw that already. IMO not as good as in JetBrains, but close enough. The question was made before v1.28 though, when that was not yet possible.
  • Machado
    Machado over 5 years
    Yeah, I thought about editing the other answer, but it would be too much change, so I wrote a new one. New users that arrive here will not notice the difference, but for <= 1.28 you could still use the TS move extension I put in the end of the answer. I also must agree that JetBrains IDEs have very nice features.
  • Machado
    Machado over 3 years
    Thank you very much. I noticed I forgot to mention; to use refactoring just click on the file path and press F2.
  • tbrodbeck
    tbrodbeck over 3 years
    This does not work for python, as far as I tested :/
  • Machado
    Machado over 3 years
    For other not JS-based languages you gona need a language processor or language server extension, like OmniSharp for C# ou IntelliPhense for PHP. There's one for Python but I don't remember it's name, just install it and it should work.