VS Code is perhaps the most popular free and open-source code editor/lightweight IDE in the world right now. Here are 5 tricks guaranteed to boost ...
For further actions, you may consider blocking this person and/or reporting abuse
They are very helpful. Here's another article that really made me happy working in VS Code: freecodecamp.org/news/here-are-som...
Good one!
#1 - Refactoring With "Rename Symbol"
This one did not work as described. When using this feature with Javascript, it only changed the name of the reference in the current module and aliased the import.
Became
The export in the module itself didn't change.
This does work for JS. If you want to rename the exports in other files like here, you must use F2 on the MyModule in the
import statementexport statement of the file it originates from. However if you want to rename sayMyModule.foo
toMyModule.bar
, you can rename it anywhere.This is because named/aliased import is valid JS syntax, and VSCode does the renaming conservatively, so it tries to change as few things as possible. If this is an import from an NPM module, it wouldn't make sense to change the exports of some files in the
node_modules
directory.Thanks for your response!
Ok, I've figured this out. Using F2 outside the place it's declared will alias it. Doing it on the import statement will also alias it.
e.g. Using F2 anywhere in this file
someFile.js
will result in
On the other hand, if you use it where it's exported it will look for all instances of it in your code and replace it.
e.g.
clocks.js
someFile.js
Would become
clocks.js
someFile.js
You're right, I didn't realize that, thanks! I guess the reason is indeed because that "blindly" renaming on import statements will mess up external stuff that we might consider static (eg. installed NPM modules).
Yeah! When you said:
It sort of made it click for me! Anyway, thanks for your article and response! Following now!
Nice advices, thanks for sharing. I discovered these progressively, and they make me save so much time today!
As for points #1 and #2, I'm working on a VS Code Extension to go even further! The idea is to provide automated refactorings to save me some time on the thing I frequently do (just like "Rename Symbol").
Maybe you'd be interested in checking it out.
It's called Abracadabra: bit.ly/vscode-abracadabra
Related to #2: with
alt + up
andalt + down
you can move lines up / down indeed. But sometimes, you'd like to move a statement above / below another one. Like, to switch from:to the following:
in a single keystroke. Moving lines up/down will mess things up until you're done, because the two objects would "merge". Thus, we tend to cut & paste indeed.
With Abracadabra, I'm working on a "Move Statement Up/Down" so you can swap them with
Ctrl + Shift + Up
for instance 😁Well, that's one example. If you feel like trying it, I'd love to get your feedbacks so I can make it better!
Anyway, thanks for this article. Have a great week 👋
This looks super cool. Thanks for making this!
Great post!
For people interested in making their own snippets & find the snippet editor confusing, you can use this awesome Snippet Generator. Works for VS Code, Sublime Text, and Atom!
Looks pretty useful, thanks for sharing!
I'd settle for a stable release that can rename files without tricky shit like sending it to Windows Explorer to rename or like having to close and restart the editor.
Can this be a conflict with extensions? If so then we get into WordPress madness disabling all "plugins" and reenabling until the offending plugin is discovered: or not.
Can you elaborate?
Every feature listed here in this article already exists since the very early versions of VSCode.
What extensions do you use? It's possible that there're keybinding conflicts. Check this out for detecting conflicts - code.visualstudio.com/docs/getstar...
What's to elaborate? From time to time VSCode will not rename a file in a workspace. This issue has been found by googling but no clear reason or solution as of late.
I've found this Managing Extensions document code.visualstudio.com/docs/editor/...
I have way too many extensions installed and its time to play the WordPress game.
I have never encountered file renaming issues (I use stable release on macOS, Linux, and insider on Windows, all with 40+ extensions, from syntax highlighters to diagram generators), but it's always a good idea to install as few extensions as possible since they can affect startup time as well. Always know your needs, and what you are installing. :)
You can always submit an issue to the VSCode project on GitHub.
Thanks for posting this. Always good to get refresher of the cool productivity hacks in VS Code. Not sure if its just my setup but for #1 Refactoring With "Rename Symbol" Ctrl + F2 worked instead of just plain F2. BTW this from my windows machine.
OMG the first one is so helpful!!!
Thank you!
Keep writing
Very glad that it helped you! 😁
Cmd + P does do Go To File. Ctrl + P just moves the cursor up a line.
My bad, fixed!
Great post thanks
Man, this is a gem and you are a gem! I'm gonna have to read all of your articles now...
Thank you, it means a lot! 🙃🙃
thanks. it was so handy tricks for a good life :))
These are great tools, thanks!
Thank you! the best tips for productivity and agile development.
Mark
Thank you so much!