Reputation: 1181
Is there a shortcut or plugin in add an import statement like
import { ApolloClient } from 'apollo-client'
I'm sure I used to do it by pressing i
space and then Tab which gave me
import {} from ''
the cursor would then jump to the from statement and then Tab would take me to the {}
Upvotes: 1
Views: 2559
Reputation: 28733
You can use the extension My Code Actions
You can define the action to be always available to include:
"my-code-actions.actions": {
"[javascript]": {
"import ApolloClient": {
//"diagnostics": ["\"(.*?)\" is not defined"],
"text": "import { ApolloClient } from 'apollo-client'\n",
"where": "afterLast",
"insertFind": "^(import |from \\w+ import )"
}
}
}
If this is related to an entry in the PROBLEMS panel (red squigle) you can add the "diagnostics"
property.
Upvotes: 1
Reputation: 11869
You can add any shortcut you want to in VSCode via the keybindings.json
file.
Open Keyboard Shortcuts (json)
option when you see it. // Inside the JSON files Curly Brackets, copy and paste the block below
{
// Follow the comment instructions
{
"key": "CTRL+SHIFT+I", // Choose the keybinding you want to use.
"command": "type", // You will use 'type' for the command to exec
"args": {
"text": "import {} from ''" // enter the string that you want to auto-type
}
},
},
/*
If you did everything correctly you should be able to use the
keybinding you choose to have it auto type your text argument*/
Upvotes: 1