How to make IntelliSense in Python behave as it does in C#? - visual-studio-code

When I write C# code in VS Code and start typing some word and IntelliSense appears and focus on some suggestion I can press dot or space and this word appears in code.
But in python I strictly have to press Enter only if I want to get suggested word. Is it possible to make IntelliSense in Python behave like it behaves in C#?

Try changing the following lines to your settings.json file
"editor.acceptSuggestionOnCommitCharacter": true,
"editor.acceptSuggestionOnEnter": "on",
"editor.quickSuggestions": {
"other": true,
"comments": true,
"strings": true
}

In addition to #DreamyPlayer's answer, add the following line to settings.json (or rewrite it, if key editor.inlineSuggest.enabled exists):
"editor.inlineSuggest.enabled": true

Related

VSCode: how to disable all suggestions/autocomplete for text in a comment

Everytime I type out periods in a comment, vscode attempts to autocomplete with some code suggestion.
As a result, I always have to type out some extra keys (eg esc) before pressing enter to complete my line, so that vscode doesn't mistakingly add some irrelevant and undesired auto-completion.
How do I disable all suggestions, snippets, autocomplete, intellisense, etc.. for comments in vscode?
I've tried many different settings for suggest and snippet, I still cannot disable them.
The oft-quoted setting is editor.quickSuggestions.comments, but this has not worked for me:
"editor.quickSuggestions": {
"other": "on",
"comments": "off",
"strings": "off"
}

Prevent Visual Studio Code to use auto-complete on PlainText

Is there a way to stop Visual Studio Code to autocomplete words, or to stop inserting snippets when working on a "PlainText" document?
I love VSC, but I use a lot of plain-text to take notes and so on. I don't want VSC to turn a 'sentence' like "I was" into:
I <i class="fas fa-car-wash "></i>
just because I pressed [Enter] after the word 'was'.
I can kill the autocomplete in total, but I like it in code files.
I just don't want it when the type is set to plaintext.
Look at language-specific settings. See https://code.visualstudio.com/docs/getstarted/settings#_language-specific-editor-settings
"[plaintext]": {
"editor.suggest.showSnippets": false,
"editor.suggest.showWords": false,
"editor.acceptSuggestionOnCommitCharacter": false,
"editor.acceptSuggestionOnEnter": "off"
},
Try setting "editor.wordBasedSuggestions": false.
You can also play around with what VSCode can suggest in Settings:
Ctrl + Shift + P => Preferences: Open Settings (UI) => Text Editor => Suggestions
#cryothic: had the very same problem as you asked for.
I was rather successfull with this somewhat simpler addition to settings.json;
no more annoying test suggestions since.
"[plaintext]": {
"editor.quickSuggestions": false,

How to set markdown snippet trigger automatically

According to the official document, https://code.visualstudio.com/docs/languages/markdown
Snippets for Markdown
There are several built-in Markdown snippets included in VS Code -
press Ctrl+Space (Trigger Suggest) and you get a context specific list
of suggestions.
Does there any way, trigger snippet automatically when I type word, because it's troublesome, press Ctrl+Space
Try setting:
"[markdown]": {
"editor.quickSuggestions": {
"other": true,
"comments": false,
"strings": true
},
},
This enables IntelliSense automatically when you start typing. By default, this will show snippets and word based suggestions (suggestions based on words in the current document). To disable word based suggestions, set:
"[markdown]": {
"editor.quickSuggestions": true,
"editor.wordBasedSuggestions": false
}
You can also set:
"editor.snippetSuggestions": "top"
If you always want snippets to show before word base suggestions
There is an inconsistency in VS Code and it is a known issue. Markdown snippets do not get auto-completion. Probably it will be fixed in next release.
Yes this is an inconsistency. Full extensions get auto (7x24) completion by default (e.g. latex, cake), some built-in extensions like Markdown do not.
https://github.com/Microsoft/vscode/issues/1617#issuecomment-166999086

Use VSCode Language specific settings for .min.js

Visual Studio Code Version 1.10 adds the ability to specify languages settings on a per language basis (*1). You put something like this in your settings.json file:
"[javascript]": {
"editor.fontSize": 100,
}
I'd like to do something more specific. I'd like to apply different rules to files that match *.min.js.
How would I do that?
I've actually got something that works, but it's a bit hacky, so I thought I'd ask.
*1) In case you want to know which ones: Use autocomplete after typing in "[]":, or see languageIds array in this file.
I'm aware beautify skips formatting min files by default. But just using "editor.formatOnSave": true, this doesn't seem to happen. Also, other non-formatting stuff like wordwrap is nice.
Here's my current solution:
"files.associations": {
"*.min.js": "javascriptreact"
},
// Hijack javascriptreact to create custom settings for min.js files
"[javascriptreact]": {
"editor.formatOnSave": false,
"editor.wordWrap": "on"
}
I'm using the fact that vscode happens to have a second type of javascript, one that isn't used my my project. Not ideal, but it seems to work.

How do you format code on save in VS Code

I would like to automatically format TypeScript code using the build-in formatter when I save a file in Visual Studio Code.
I'm aware of the following options, but none of them is good enough:
Format manually Shift + Alt + F
Format on type "editor.formatOnType": true
It formats the line when you press enter. Unfortunatelly, it leaves it unformatted when you mouse-click another line or press up/down arrow.
Use existing extension
I tried this one, but it does not seem to work too well.
Use beautify "beautify.onSave": true
It does not work with TypeScript
Write custom extension
It's tricky if you want to handle autosaves and builds correctly.
As of September 2016 (VSCode 1.6), this is now officially supported.
Add the following to your settings.json file:
"editor.formatOnSave": true
No need to add commands anymore. For those who are new to Visual Studio Code and searching for an easy way to format code on saving, kindly follow the below steps.
Open Settings by pressing [Cmd+,] in Mac (or [Ctrl+,] in Windows/Linux) or using the below screenshot.
Type 'format' in the search box and enable the option 'Format On Save'.
You are done. Thank you.
If you would like to auto format on save just with Javascript source, add this one into Users Setting (press CmdShiftP or CtrlShiftP then type Open Settings (JSON) to open settings.json file)
"[javascript]": { "editor.formatOnSave": true }
For eslint:
"editor.codeActionsOnSave": { "source.fixAll.eslint": true }
For neet formatting for any language you can use Prettier - code formatter.
After applying this you can format code Alt + Shift + f
The best to avoid conflicts is defining individual formatters for each language, for instance if I am working with Rust and Typescript I would like to format code using the extensions Rust-Analyzer and Prettier respectively, therefore on my .vscode/settings.json:
{
"editor.defaultFormatter": null,
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
}
Remember that both Prettier and rust-analyzer extensions must be installed first.
For MAC user,
add this line into your Default Settings
File path is: /Users/USER_NAME/Library/Application Support/Code/User/settings.json
"tslint.autoFixOnSave": true
Sample of the file would be:
{
"window.zoomLevel": 0,
"workbench.iconTheme": "vscode-icons",
"typescript.check.tscVersion": false,
"vsicons.projectDetection.disableDetect": true,
"typescript.updateImportsOnFileMove.enabled": "always",
"eslint.autoFixOnSave": true,
"tslint.autoFixOnSave": true
}
After hours of struggle... below steps worked.
Full details below.
Install this extension
https://marketplace.visualstudio.com/items?itemName=pucelle.run-on-save
Add below json, to below file:
File:
<your-project-directory>\.vscode\settings.json
OR
%UserProfile%\AppData\Roaming\Code\User\settings.json
JSON:
NOTE: Make sure commas before and after below block.
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 1000,
"runOnSave.statusMessageTimeout": 3000,
"runOnSave.commands": [
{
"match": ".*\\.*",
"command": "editor.action.formatDocument",
"runIn": "vscode"
}
],
Now, when the code is changed, after 1 second, it gets formatted & saved automatically.
For me formatOnSave wasn't working because I had prettier installed and hadn't yet chosen between the built-in and prettier as my default formatter.
To trigger the selection dialog I had to press Alt + Shift + f on my json file.
First, you need to choose the formatter which you have just added as an extension.
Press ctrl + alt + f and choose the formatter that you want from the dropdown.
Post that with every save it will get automatically formatted.
If you use Prettier and this line
"editor.formatOnSave": true
Doesn't work to format on save, you might need to add another command to settings.json
"editor.defaultFormatter": "esbenp.prettier-vscode",
In addition to enabling setting Format On Save, for python developers, you may need to install autopep8 package which is used by vscode as default to format the python code when the code is saved.
pip install autopep8
and then, press ctrl + s to see changes.
Goto settings and search format
check Editor: Format On Save
or follow these steps