Normally, in Visual Studio Code, if you type in a variable or function that isn't imported, then Visual Studio Code will auto-correct it, if you select it.

For example, if I am typing half the name of a function, it will infer that I want a function, and when I hit Tab/Enter, it will autocomplete it, and import it.

See the GIF below for a visual example.

Answer from Viradex on Stack Overflow
Top answer
1 of 2
6

Normally, in Visual Studio Code, if you type in a variable or function that isn't imported, then Visual Studio Code will auto-correct it, if you select it.

For example, if I am typing half the name of a function, it will infer that I want a function, and when I hit Tab/Enter, it will autocomplete it, and import it.

See the GIF below for a visual example.

2 of 2
5

Create a clone of the Rust shortcut

Since there is already a shortcut that does what you want (albeit in a different language), you may be able to create a new shortcut based on the existing one.

First: open your keyboard shortcuts, and do a "reverse-shortcut" search for Ctrl + .. There's an icon near the right side of the search input that switches the search behavior to this:

You may find multiple matches; study them to identify the Rust import command that you like. In particular, take note of the "Source" column: if Source is "Extension," that means you're getting the Rust behavior from an extension, and you may need to find (or create) a similar extension that targets JS/TS. (I suspect you will, because I don't have any commands related to imports in my VSCode.) The next step requires that you copy the value of the Where column, so do that now.

Second: look at the "Command" column for the name given to this behavior. If the name is specific to Rust, do a new search for a similar command that doesn't target Rust. If there is such a command, you just need to configure it to run when you like: edit that shortcut and paste the "When" value from behavior; this may require a hand-edit if the When from the Rust command mentions anything specific about Rust (e.g. if it includes editorLangId == 'markdown', change that to 'javascript' and add alternative for typescript as well).

If there is no auto-import command that is language agnostic, and none that is specific to JS/TS (again, I don't see one in my VSC), you will have to rely on the Intellisense-based option, or find (or create) an extension that does this. Creating an extension is a whole other topic.

🌐
DEV Community
dev.to › krisplatis › auto-add-missing-imports-on-file-save-in-vs-code-1b89
Auto-add missing imports on file save in VS Code ✨ - DEV Community
March 26, 2025 - Note: When there is more than one possible suggested import path for a token, such a missing import won’t be auto-added. However, you can configure a keyboard shortcut to auto-add missing imports (and it can handle a situation when many import paths are suggested; e.g.
Discussions

vscode extension for auto import ?
I am looking for some vscode extension for auto import with shortcut . How can I import Model / Controller with shortcut in vscode ? More on github.com
🌐 github.com
2
1
vscode extension for auto import ?
I am looking for some vscode extension for auto import with shortcut . How can I import Model / Controller with shortcut in vscode ? More on github.com
🌐 github.com
2
1
October 6, 2022
typescript - Visual Studio Code Automatic Imports - Stack Overflow
Yes, auto-imports work great on Mac out of the box regardless of if your project's version of typescript matches with what shipped with VScode, but in other OS's, namely linux, this is not the case, and you must point to the workspace's version of TS as I explained in my answer. More on stackoverflow.com
🌐 stackoverflow.com
Is there an option or extension for VS Code to quickly import a file relative to the file I'm currently working on?
What you are describing is how it works by default for me, so it might be some issue with your intellisense setup. Also, I highly recommend setting up some sort of absolute imports, if you find yourself frequently needing to do deep cross module imports https://medium.com/@yan.code/why-and-how-to-use-absolute-path-imports-in-typescript-projects-86f66ec7b349 More on reddit.com
🌐 r/webdev
5
3
September 3, 2024
🌐
Reddit
reddit.com › r/vscode › can't find this shortcut. need help! auto import.
r/vscode on Reddit: Can't find this shortcut. Need help! Auto Import.
January 18, 2022 -

So a while ago, I remember having a shortcut that would suggest auto imports for files. For instance, I'm a web dev and I use React as my main framework. I remember back when I started, if I wanted to auto import a file, I would type the file's name name and VS would suggest the right imports.

However, I know there is a shortcut that does just that. On PC I think it's Ctrl + space. I'm on macOS 12.1 and I have my Cmd + space set to spotlight/Alfred (and I need it).

What is the shortcut's name so I can change the shortcut or just, what is the actual shortcut ?

Thanks!!

🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Auto Import Relative Path - Visual Studio Marketplace
Extension for Visual Studio Code - Streamline your imports with instant relative path generation. Copy or auto-import files for JavaScript, TypeScript, CSS, HTML, and Markdown in a single command—no more manual path typing or memorizing!
🌐
Medium
medium.com › @bikash_jaiswal › 4-shortcuts-that-boosted-my-website-development-speed-in-vscode-66d25f6d0bf1
4 shortcuts that boosted my website development speed in VSCode. | by Bikash Jaiswal | Medium
January 8, 2024 - Let your VSCode remember, find and import your components and packages for you. Just press tab key after you write <componentName>, VSCode should be smart enough to auto import the components and packages.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Import Helper - Visual Studio Marketplace
December 5, 2021 - Extension for Visual Studio Code - quickly import modules, aliases, and symbols via a search (for typescript, javascript, and svelte)
Find elsewhere
🌐
Reddit
reddit.com › r/webdev › is there an option or extension for vs code to quickly import a file relative to the file i'm currently working on?
r/webdev on Reddit: Is there an option or extension for VS Code to quickly import a file relative to the file I'm currently working on?
September 3, 2024 -

When I'm working on a project with hundreds of files across a lot of folders & sub-folders, it's really annoying when VS Code's auto import doesn't recognize what I'm trying to import and I have to import it manually. For example, if I'm working on src/features/users/account.jsx and I need to import a method from src/utils/userHelpers.js, but VS Code doesn't automatically suggest the method/file I'm trying to import, it's annoying to manually write an import statement and have to count how many directories I need to go down, write out '../' for each, and then write out the rest of the directory path.

It would be really nice if within my VS Code workspace, I could just right click a file in VS Code's Explorer and select an option like "Import to currently open file" to do this all for me. Such that pressing this button figures out the relative path for me and adds "import userHelpers from "../../utils/userHelpers" to the top of the file I'm currently working on. Or even if it could just copy the relative path to my clipboard so I don't have to figure out the relative path myself, that would be really nice.

Does something like this exist for VS Code? If so, how do I use it?

🌐
YouTube
youtube.com › watch
Visual Studio Code Extension - Auto Import - YouTube
Visual Studio Code Extension - Auto ImportIn this video, we take a look at the Auto Import extension within Visual Studio Code. Prefer written content or wan...
Published   July 17, 2017
🌐
freeCodeCamp
freecodecamp.org › news › react-shortcuts-that-will-instantly-boost-your-productivity
5 React Shortcuts That Will Instantly Boost Your Productivity
January 19, 2021 - When you use auto import, it makes working with projects of any scale easier, because you no longer spend half of your time writing import statements. Along with having Prettier for all of the code that we write, VSCode gives us a shortcut called organize imports that does just that.
🌐
DEV Community
dev.to › shanesc › how-to-get-javascript-auto-import-suggestions-working-in-vs-code-aig
How to: Enable JavaScript auto-import suggestions in VS Code - DEV Community
November 22, 2024 - Now that VS Code knows to treat all your JS files as an explicit project, auto-import suggestions will populate with all your relevant exported code.
🌐
GitHub
github.com › microsoft › vscode › issues › 47002
Ctrl + . (auto import in typescript) no longer works · Issue #47002 · microsoft/vscode
March 30, 2018 - Ctrl + . (auto import in typescript) no longer works#47002 ... bugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugjavascriptJavaScript support issuesJavaScript support issuestype...
Author   microsoft
🌐
Devsense
docs.devsense.com › vscode › editor › auto-import
Auto Import - PHP Tools - Documentation
auto-import-grouped: imports the alias as auto-import, unless there is already use with the same namespace. Such use is upgraded to a group use. fqn: inserts fully qualified name upon completion. ... In case there is a missing import, a quick code actions is provided with available options. To open the quick fix, use either a shortcut (default Ctrl+.) or click onto a lightbulb icon.
🌐
Medium
medium.com › @sebastiantolomeo › how-to-automatically-organize-imports-in-visual-studio-code-e80d87b4f263
Automatically Organize Imports in Visual Studio Code | by Sebastian Tolomeo | Medium
June 5, 2022 - This meant I had to remove the curly braces from every single import statement for that context across the project. I thought that VS Code had to have some way to do this automatically without having to go into every single file and removing them manually, so I right clicked and noticed an option named Source Action
🌐
GitHub
github.com › microsoft › vscode › issues › 95831
Add keyboard shortcut for 'Add all missing imports' · Issue #95831 · microsoft/vscode
April 22, 2020 - microsoft / vscode Public · Notifications · You must be signed in to change notification settings · Fork 40.3k · Star 186k · New issueCopy link · New issueCopy link · Closed · Closed · Add keyboard shortcut for 'Add all missing imports'#95831 · Copy link · Assignees ·
Author   microsoft
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Auto Import - ES6, TS, JSX, TSX (VSCode Extension)
Extension for Visual Studio Code - Automatically finds, parses and provides code actions and code completion for all available imports. Works with JavaScript and TypeScript. [Forked]
🌐
Reddit
reddit.com › r/vscode › does anyone how to make auto-import a thing on java vscode?
r/vscode on Reddit: Does anyone how to make auto-import a thing on java vscode?
March 16, 2022 - When you need to import, you can use the shortcut key Ctrl +. .In this way, you can also quickly import the packages that you need. ... Intellisense AutoComplete Not Working anymore.