CSS Files Opening Up as Plain Text in VS Code - visual-studio-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 ,).

Related

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.

Can't edit files in Vscode

I've just started using Vscode and have a created a WebAPI project. On trying to open any of the default code files (Startup.cs and Program.cs) whatever I type starts to appear in the blue bar as shown below instead of where I have placed the cursor. I have no idea what's going on or what that blue bar is.
I am able to add my own code files and edit these as I would expect.
I'm running Vscode 1.29.1 on Win 10 on a Dell Latitude 12 7275. The vscode extension
Enabled extensions :
That's caused by Vim extension. Uninstall or disable it, otherwise use insert key on your keyboard to put it in insert mode.
I'l leave this here for future readers
Basically, if I split files in tabs in VS Code, I could work with the files on the left hand side but could "read-only" all the files on the right hand side.
When I went to the extensions tabs I noticed that whatever I typed was being typed in the field in the extensions search bar. After deleting that, and clicking back on the "Files" tab, it went back to normal and can basically edit files on the both sides of my split screen.
If cannot type
Check where whatever you type is going (e.g. Extensions > Search bar)
Delete wherever it's being typed, and click back on the "Files tab"
Check if it works
I had to change the parent folders permission...
Try changing the entire folder to:
Read & Write: Allows a user to open the item and change it.
https://support.apple.com/guide/mac-help/change-permissions-for-files-folders-or-disks-mchlp1203/mac

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

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.

Change VSCode Default Language for new files?

Is there a way in Visual Studio Code to change the default language that is used for new files?
By default if you open a new file, it's set for "Plain Text", I want this to be "HTML" instead.
I am often copy pasting HTML into VSC, editing a bit, then copying it back to a CMS I am using (the CMS editor is horrible). I don't want to save the code on my computer at all, just edit it a bit with HTML syntax highlighting, but I want that to be the default.
You can now set the default language at either the user or workspace settings level using files.defaultLanguage:
"files.defaultLanguage": "html"
This can be done as a one off by changing the language mode:
F1 to launch command palette
Type lang, enter
Type html, enter
Now you can do this change. Check out
"files.defaultLanguage" in settings.
With v1.42 you can either set
"files.defaultLanguage": "${activeEditorLanguage}"
and when you open a new untitled file with an html file as the last active file, the new file will automatically be assigned a languageMode of HTML.
Alternatively, pasting any html code into a new untitled file from a vscode editor will automatically be detected and the languageMode set to HTML. Unless you have specifically set
"files.defaultLanguage": "plaintext"
then the languageMode will not be automatically detected as of v1.43.
Also see https://stackoverflow.com/a/68596936/836330 for a preview language detection feature in vscode 1.59.
A slightly quicker way to accomplish what Daniel had answered:
Press Ctrl+K, then M
Type html, then press Enter
I had a similar issue with VS Code. I wanted to default to Python when opening new files.
Solution: Click on File > Preferences > Settings. In the search area, Type: "files.defaultLanguage". Then fill in the language of your choice.
Perhaps you could create a scratch file with the .html extension? Open that when you need to do some copy/paste editing.

Eclipse treating file as plain text

I've got a small homework project, and for whatever reason Eclipse has decided to stop highlighting syntax or allowing intellisense or goto definitions or anything in this Main.java file. I've tried rebooting it, and the computer, but had no luck.
The thing that really has me confused is that it's still compiling and running the code correctly (eg, changes I make in Main.java are compiled and run - it's not running old Main.class files), so it's still in the build path ... right?
Any ideas?
Right click on the file in the Package Explorer and choose the Open With menu. You will probably find that Text Editor is selected, choose Java Editor to open the file with the correct editor.
The Open With menu selection is remembered so you should get the Java Editor in future, but equally if you choose the plain text editor that is also remembered.
I suggest finding a way to reset any setting you might have set by accident. Not saying that you did it. But just to make sure, just try it out. If you customized the preferences already, you could make some kind of note of the settings, then change it. If that doesn't work, let me know. Good Luck!
Copy the text somewhere, delete the file, and then add a new class (of the same name) and paste the text back.