VS Code - Turn off auto close tags, but leave on autocomplete - visual-studio-code

Recently switched from Sublime Text 3 to VS Code. Overall pleased with the switch except for this one little thing that's just annoying enough to be a dealbreaker if there's no solution. In ST3 if I type, say, a <div>, it doesn't automatically drop in a </div>, which is nice because I'm often pasting it in and don't want it closed right there.
What ST3 DOES do, however, is complete the tag the moment I type </. It autofills div> the moment I type the forward slash. This is the behavior I want from VS Code. I can't find any mention of this anywhere which is completely baffling. I know how to autoclose tags, but that's no good becasue then I have to manually close them. I want VS Code, like ST3, to autocomplete the tag for me, just not immediately.

Go to File > Preferences > Settings, search for html.autoClosingTags and set it to false.
This will make it so when you type <div>, it won't insert </div> automatically, but if you start typing </, it won't close the tag automatically. You can press ENTER to make it autocomplete for you.
Or you can leave this option enabled and when you type <div> and it autocompletes, you can just press CTRL + Z.
More information on this behavior here.

Add this to settings.json to make it work like Sublime Text:
"html.autoClosingTags": false,
"auto-close-tag.SublimeText3Mode": true

Go to Settings, search for "auto closing" and enable/disable these options as needed
Or set them in your settings.json file like so:
"html.autoClosingTags": false,
"typescript.autoClosingTags": false,
"javascript.autoClosingTags": false,

On Windows/Linux - Ctrl + Shift + P
On MacOS - Cmd + Shift + P
In the search box type settings.json
paste the following line there
"html.autoClosingTags": false

A very simple trick i learnt
If you want to disable tags auto completion for just a single task for example. To save a file without vscode adding closing tags. Just set a different language mode for that file.
Change from the inferred one i.e html to Batch, Diff ignore. The options on vscode are many. This will enable you to save the file without addition of any closing tags.
After you are remember to reset the language mode to Auto Detect.
TLDR;
To access language mode-:
Use the command pallete and search Change Language Mode or
Find a shortcut at the bottom right section on Vscode.

Related

Prevent ctrl-B from setting bold font while working with md files with the Markdown All in One extension

In VS Code, when you are working with a markdown file with the "Markdown All in One" extension active, ctrl-B sets the selected text to bold by surrounding it with **
The problem is that I use the ctrl-B keyboard shortcut all the time to show/hide the side bar.
Is there any way to disable that emboldening shortcut (or define an alternative one) when working with Markdown files, and to use it for hiding the side bar?
edit: the problem was that I had the 'Markdown All in One' installed
I don't think this can currently be done without uninstalling / deactivating your "Markdown All in One" extension. If you look at the list of keybinding actions it offers (see those that start with markdown.extension.editor.toggle), there are ones for toggling code spans, blocks, math, lists, but none for toggling bold and italics, which I find strange. No dice either searching for suggestions in the keybindings.json with "markdown.extensionbold".
So either I'm missing something, or you need to make a feature-request on their GitHub. If you do, post a link in the comments here for posterity.
As a last resort to get a fix right now, you could just remap your toggle-side-bar keybinding to something else.

Vim EasyMotion for VS Code not activating

Does anyone use Vim with VSCode?
For some reason, my <leader> key (space), does not activate the easy-motion plugin (I made sure it is enabled in the settings), but just moves the cursor to the right once.
I am new to VS Code, am I missing something? I still haven't figured out how .vimrc works with VS Code.
TIA!
It's not nessesary to use .vimrc file for vscode unless you want some customized behaviors.
Make sure you've enbaled the easymotion in vsvim settings:
"vim.easymotion": true
(in your settings.json file)
When it comes to VSCode, easymotion will be triggered by double press <leader> key. Different from Terminal Vim, for example: (in your case <leader> is set to space)
space + space + 2 + s
after you press the above keys, your status bar should look like
this.
Hope it would help you get into Visual Studio Code quickly.
As far as I know, vim mode in VS code isn't configured by .vimrc file, instead, it's configured by setting.json. You can find how to configure them in this README.md.
Check that:
"vim.leader"is set to <Space>
go to preference -> Keyboard shortcut in VS code. Make sure that you did not customize any command to any shortcut starting with <space>. (I made this mistake before)
the timeout length of the leader key is pretty short, make sure you press, let's say, 'w' key right after <leader><leader>
I hope this would help

CSS Files Opening Up as Plain Text in VS Code

For some reason, whenever I create a new file and give it a css extension, the language mode is set to plain text. That is not the usual behavior and I don't know why it is acting that way.
Does anyone know how to fix that?
Thanks.
Click to the language at the right bottom bar of VSCode
Select Configure File Association for '.css'
Find CSS and select it.
You could run into problem cannot finding CSS in the last step I mentioned above, then here might be the fix for it btw:
Press Ctrl + , to open the Settings window.
Click Open Settings (JSON)
Find a line where there is
"files.associations": {
"*.css": "Plain Text"
}
and delete it, make sure the json file still in a correct format after deleting (no missing or extra comma ,).

How do I select all text in vistual studio code?

In visual studio code (1.29.1) ctrl+a doesn't do anything for me. I checked keyboard shortcuts and it's mapped to a few select all actions (editor.action.selectAll, etc.) but when I'm in a file and press it nothing happens. How do I select all text in the current file in visual studio code?
Thanks for the comments, it make me realize it must be an environmental issue. Turns out if you have any mapping starting with a key combination that will lock that mapping to the key combo and you can't use it for anything else.
To make save all ctrl+shift+s I had to re-map save as and I mapped it to ctrl+a+s, so everytime I hit ctrl+a it just waiting for second key. In the status bar at the bottom of my editor it said something like "Ctrl+a detected, waiting for second keystroke", which means Ctrl+a won't work on its own. I re-mapped Save As to some unused key combo and it fixed select all.
This question was luckily answered on another thread
I'll post the OG answer here, nonetheless.
Most new comers to VS-Code could resolve this issue with the 2nd method provided by the OG answer:
Goto File > Preferences > Keyboard Shortcuts
in the search bar type this Select All
There's should a couple of results, you'll obviously want the "Select All" result
right click on his line and click on Change When Expression
a textbox would be highlight for you to fill in text. type editorFocus
press enter and done!
The OG answer provides image if you need to confirm that you're doing it right.
side-note: This issue bugged for more than 3 years and is the main reason my I used VS-Community over VS-Code.
So it's nice to finally be able to work normally in this very robust customizable IDE text-editor.

How to disable Ctrl-Click in VS Code

I want to know if it's possible to remove the key bind on Ctrl-Click for the goToDefinition (F12) editor action.
This is so annoying, every time i try to Ctrl+C/V it trigger and go to the definition cause I'm holding Ctrl while I'm highlighting the code with my mouse.
I have search for it on google but all y can change is the F12 key bind for goToDefinition which is not what I want.
--- Update
This is the feature I want to disable
I need to remove the ctrl+click key bind.
Even if I replace it, it doesn't work.
-- Update 2
I finally found something on the subject Here
But for me it doesn't work at all.
-- Update 3
Created a new issue on GitHub (#7827)
Look at it if you wanna see the update on the request.
At the time of writing (2022) you can turn off this with workaround by setting following setting to 'ctrlCmd'.
How to open setting page in vs code?
Ctrl+Shift+P and enter open setting (UI)
Note that if you are also looking for Ctrl+Click for word selection, it is still not possible. See my another answer.
And yea, the dreaded (and famous) issue #3310 is never really happened, even after 6 years.
There is a VS Code feature request for this on GitHub, under the more general heading Allow customization of mouse shortcuts.
Anyone interested in this VS Code feature should comment/vote there. (The Ctrl-click-specific GitHub posts have been closed off and linked to this one. Ex. #16974)
Add the following lines in keybingings.json to disable (actually override default behaviour) mouse+ click
[
{ "key": "ctrl+[mouse button]", "command": "cursorWordLeft",
"when": "editorTextFocus" }
]
To open key bindings file, traverse
File > Preferences > Keyboard Shortcuts