Is it possible to apply syntax highlighting of one filetype to another in Visual Studio Code, like in Notepad++? - visual-studio-code

Somebody who used Notepad++ clearly knows about applying custom syntax highlighting to any text, by selecting an option from the "Language" menu, as shown the screenshot below;
This way, one can highlight the text, as he wish. I would like to know, is there any similar mechanism in Visual Studio Code editor, so that I can manually highlight the text even if its not done automatically.
Thanks.

You can change the Language used for a particular instance by clicking on the Language ID field in the Status bar and select the new language from the list.
This executes the command workbench.action.editor.changeLanguageMode or Change Language Mode from the Command palette.
To do a permanent Language ID selection based on the file extension define a setting
"files.associations": {
"*.myext": "html",
"*.myfoo": "css"
}

Related

How do I insert a snippet into a VSCode file?

I've used snippets before but it's been a very long time, so I don't remember how to insert them.
I already edited my settings according to Tab autocomplete in Visual Studio Code doesn't work, but it's still not working.
"editor.tabCompletion": "on"
"emmet.triggerExpansionOnTab": true
When I type the name of the snippet (e.g., html-boilerplate) in a file, no autocomplete suggestions come up. Then, if I tab, it just creates the name of the snippet as a tag (i.e., <html-boilerplate></html-boilerplate>).
If I open the command pallet (ctrl+p) and type "insert," the name of the snippet comes up, but clicking on it just opens the snippet file itself.
I also tried ctrl+shift+p, typing >insert, and then selecting "Insert Snippet," but then it just says no snippets are available (neither the defaults nor the ones I've created). Source: https://adamtheautomator.com/vs-code-snippets/
Your time and assistance are greatly appreciated!

How can I make a plugin for Vscode to change colors of a file type?

for example .xlp is my file type and name is code.xlp I want to highlight some code.
or some colors ?
Somethings like this
Inno Setup For VS code
In case you don't want to write custom extension, try manual configuration of 'file association' for '.xlp' files.
This will tell VS Code to highlight content of '.xlp' files as language of your choice.
For example, I set it to C# and it looks like this:
Steps for this configuration:
Inside of '.xlp' file press ctrl + P to open navigation field,
Search for >Change Language Mode,
Choose Configure File Association for '.xlp',
From dropdown list choose language you like.
As mentioned inside a comment you must write an extension for VS-Code to have your custom syntax highlighting for those files.
There is a good documentation available at:
https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide
At the mentioned web page you will find also more information about how to write your own extension and how to deploy it etc.

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 ,).

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.

How to activate Markdown user snippets in Visual Studio Code?

User Snippets are an awesome feature of Code, however, I can't get them to work for Markdown files. A markdown.json file exists and is editable, but I can't get snippets defined in that file to activate (using Tab like for other languages). Is there a different activation method for these snippets or are they just not supported yet?
EDIT: Here's the contents of the markdown.json file just in case I'm doing something wrong there.
{
"Markdown comment": {
"prefix": "comment",
"body": [
"<!--- \n --->"
],
"description": "A Markdown comment"
}
}
Open the editor
Go to File -> Preferences -> User Snippets
Select Markdown. The file C:\Users\YOU\AppData\Roaming\Code\User\snippets\markdown.json will be opened
Paste your snippet into the file and save it
From now on you can use the snippet in all .md files.
In case the snippet suggestion doesn't popup when you type "comment" then you should type CTRL + Space to force it.
https://github.com/Microsoft/vscode/issues/26108
in case you mean no popup quick suggestion, the link is the cure.
"editor.quickSuggestions": true
add this to user setting then you should be able to see the popup snippet suggestions
https://github.com/Microsoft/vscode/issues/1617#issuecomment-166999086
Full extensions get auto (7x24) completion by default (e.g. latex, cake), some built-in extensions like Markdown do not.
You have to type CTRL + Space to force it.