How can I refactor file names in Visual Studio Code?
Solution 1
Actually you can. Natively on Visual Studio Code (>= v1.28) with import path renaming:
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.
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, 2022Comments
-
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 over 5 yearsI 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 over 5 yearsYeah, 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 over 3 yearsThank you very much. I noticed I forgot to mention; to use refactoring just click on the file path and press F2.
-
tbrodbeck over 3 yearsThis does not work for python, as far as I tested :/
-
Machado over 3 yearsFor 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.