I use CSS like this:
const styles = {
foo: {
color: 'red'
}
}
<div className={styles.foo} />
and I want emmet to expand .foo to <div className={styles.foo}></div>
I don't see any reference to class or className in emmet's config file.
Also looked into preferences.json and didn't find a solution.
It seems very simple to do.
What am I missing here?
My code editor is vscode.
Press Ctrl + , or Cmd + , or File > Preferences > Settings. This will open Settings window.
Go to Workspace tab > Extensions > Emmet.
For the current vs code new version, you'll see a menu called Included Languages. similar to this:
After enter javascript in the item box and after type javascriptreact in the value field and finally press Add item. Your final output must look like the image below:
Emment configuration or enabling is editor specific. In VSCode, You need to enable it for current work space. Follow theses steps. (If you are busy, follow bold letters.)
Press Ctrl + , or Cmd + , or File > Preferences > Settings. This will open Settings window.
Go to Workspace tab > Extensions > Emmet. You'll see Edit in settings.json under Preferences.
You'll see following content by default (my version is 1.35.0) for the new version please see Kevin's comment
{
"folders": [],
"settings": {}
}
Change the content to below
{
"folders": [],
"settings": {
"emmet.includeLanguages": {
"javascript": "javascriptreact"
}
}
}
See more about emmet configuration
Save the file Ctrl + S.
Go to your .jsx file, type .myClass. Press tab. It should expand to following.
<div className="myClass"></div>
Currently, obtaining {myClass} instead of "myClass" is a pending feature request. But you can go to to <VSCodeInstallationDir>/resources/app/extensions/emmet and apply the patch. (using npm i)
I had this same question. I found this post, and I've concluded emmet doesn't support setting class as anything other than a string. User Freestyle09 suggested user snippets, I've gone ahead and made one for myself, it's not a full solution, but it's the workaround I've settled with.
I'm just using emmet to create the html, and then putting my cursor in to the element, and typing " cn", and I have a user snippet defined for javascript and jsx as follows:
"jsx class name": {
"prefix": ["cn", "className", "classname"],
"body": ["className={${1:styles}.${2:class}}"]
}
there's probably a more elegant way to do it, feel free to build from there. I started with the user snippets page
Related
For VS Code, I use rust-analyzer to handle syntax highlighting and flychecking.
How do I remove the inlay type and parameter annotations in grey below?
In Visual Studio Code you can easily do this.
Open the settings page (Ctrl+,)
Search for "rust-analyzer inlay"
Uncheck things you don't want
In your case that would be "Parameter Hints" and "Type Hints"
If you're not using Visual Studio Code you'll need to manually edit the JSON config file of rust-analyzer (helpful link to the documentation). Basically
Open the JSON config file in your favourite text editor
Add a new property to the root of the JSON object like so:
{
"inlayHints": {
"typeHints": false,
"parameterHints": false
},
// further configuration
}
Update Sept 2022.
They now use VSCode builtin inlay function from 1.67
I setup mine as follow:
{
"editor.inlayHints.enabled": "offUnlessPressed"
}
Then you can toggle them with Ctrl + Alt pressed.
Old Answer
There is now a togglable command (ctrl+shit+p) : Rust Analyzer: Toggle inlay hints
For VS Code, I use rust-analyzer to handle syntax highlighting and flychecking.
How do I remove the inlay type and parameter annotations in grey below?
In Visual Studio Code you can easily do this.
Open the settings page (Ctrl+,)
Search for "rust-analyzer inlay"
Uncheck things you don't want
In your case that would be "Parameter Hints" and "Type Hints"
If you're not using Visual Studio Code you'll need to manually edit the JSON config file of rust-analyzer (helpful link to the documentation). Basically
Open the JSON config file in your favourite text editor
Add a new property to the root of the JSON object like so:
{
"inlayHints": {
"typeHints": false,
"parameterHints": false
},
// further configuration
}
Update Sept 2022.
They now use VSCode builtin inlay function from 1.67
I setup mine as follow:
{
"editor.inlayHints.enabled": "offUnlessPressed"
}
Then you can toggle them with Ctrl + Alt pressed.
Old Answer
There is now a togglable command (ctrl+shit+p) : Rust Analyzer: Toggle inlay hints
VSCode is still very new to me. Every time I open ah HTML document from my class assignments (or any ordinary HTML document for that matter) VSCode defaults to "Django HTML" over regular "HTML" formatting.
I'd like to remove Django HTML as the default so that any time I open up a .html document the default formatting is regular HTML.
First type CRTL + K, then press M
Click "Configure File Association '.html'..."
Type "HTML" into the search bar
Select "<HTML>"
If you do the same first 3 steps again, you should now see "<HTML> Current Default" which confirms that you have done these steps correctly.
Add this to your settings.json
"files.associations": {
"*.html": "html",
}
I am using visual studio code for writing html but it doesn't have the feature of identifying closing tag for the current selected one.
How can I achieve the same?
Here is how it looks on VS Code:
Can you suggest any extension or how can I achieve this?
VS Code 1.7.1
install this extension
highlight-matching-tag
and change the settings.json to
"highlight-matching-tag.leftStyle": {
"borderWidth": "0 0 0 3px",
"borderStyle": "dotted",
"borderColor": "red",
"borderRadius": "5px"
},
I think you chose PHP or something else for "language mode", change it on HTML
I'm not sure if you have any extensions installed that break the highlighting? If I use your example, it highlights the closing tag fine by default:
Additionally, there is a builtin Emmet command that jumps between the beginning/closing tag. In the command palette, you can search for 'Emmet: Go to Matching Pair".
If you bind it to a shortcut, you can press that for example twice to see the cursor jumping between your tag. The name of the command to bind is editor.emmet.action.matchingPair
I was having the same issue and HTML snippet extension solve it. Just install it Html snippet
and just do some changes in setting, goto file->preferences->setting,
you can now see User settings in the right hand side, add the following code
,"files.associations": {
// extension name : html
"*.php": "html",
"*.html": "html"
}
and you are ready to go. Enjoy :)
The best visual way that i found to do this is with a plugin highlight-matching-tag
"highlight-matching-tag.styles": {
"opening": {
"full": {
"highlight": "rgba(165, 153, 233, 0.3)"
}
}
}
VSCode now supports matching tag highlighting by default:
Install "Bracket Pair Colorizer" extension.
File -> Preference -> Settings -> User Settings(Text Editor). You can edit in json view.
first confirm your visual studio have this extension it install default but for safe side you can check and solve highlight problem with matched div with this steps:
Go to the visual studio and type Ctrl+P
Make sure
Open preferences > setting
Paste this:
"editor.occurrencesHighlight": false,
"highlight-matching-tag.styles": {
"opening": {
"name": {
"underline": "red"
}
}
}
first line for disabled highlights.
you can choose color : red or anything else
may be it's help to you
#thank you
I was having this issue too. If you click and drag it selects all words with that text highlighted, but if you just single click it seems to select the closing tag. So yeah just single click a tag to get the pair, don't double click or click and drag.
I was having this same issue with Some Tags matching and highlighting while others don't.
The Weird thing was if I created a new file, and put a bunch of tags in they all highlighted correctly.
Turns out that that the person that created the original page used </br> for line breaks. This broke the highlighting of open and closing tags where a </br> happened between them. I changed the </br> to <br /> and everything is happy now.
It also happened with <link></link>, that I fixed by removing the closing tag.
I would suggest that if you are having this issue to look for closing tags that are not needed/ required.
How would you filter the files shown in the folder view in Visual Studio Code?
Reference: Filter files shown in folder
Hiding files and folders
The files.exclude setting lets you define patterns to hide files and folders from several places in VS Code like the explorer and search. Once defined, files and folders matching any of the patterns will be hidden.
{
"files.exclude": {
"**/*.js": true
}
}
Hide derived resources
If you use a language that compiles to another file at the same location of the source file, like TypeScript does to JavaScript, you can easily set an expression to hide those derived files:
"**/*.js": { "when": "$(basename).ts"}
Such a pattern will match on any JavaScript file (**/*.js), but only if a sibling file with the same name and extension, *.ts in this example, is present. The same technique can be used for other transpiled languages, like Coffee Script or Less/Sass, too.
Source: VS Code v0.5.0 (July 2015)
In version after VScode 1.70 (July 2022) all you need to do is press Ctrl+F or F3 to search.
Please refer following post
Searching in Explorer panel after VSCode 1.70
Only applicable for v1.69 and below.
Step #1
Click on Explorer window. This is critical as without focus on Explorer it will not work.
Step #2
Start Typing name you want to filter. It's weird that there is no textbox to take input but... take a leap of faith and type. You will see your typed text in top-right corner in brown background. Now hover on that text.
Step #3
Click on 3 stacked lines to filter..
They look like hamburger menu but they are not. They are saying if it's filtered or not. They are toggled between filtered and just highlight. So, make sure they are like inverted pyramid.
That's it. It should be filtered now.
If you only want to change the setting for this project, then do the following:
File > Save Workspace As > ... enter your {project name}
Then open file: {project name}.code-workspace
And update section settings.
Sample:
{
"folders": [
{
"path": "."
}
],
"settings": {
"files.exclude": {
"**/*.log": true
}
}
}
VScode 1.70 (July 2022) should improve on this "tree filter" feature.
(Available today in Code insiders)
See issue 70646 and PR 152481:
Support find widget in lists/trees
This PR replaces the existing list/tree type filter:
with an bona fide find widget:
While a seemingly simple change, this has some (desired) consequences when searching/filtering in trees. Namely:
We will restore simple keyboard navigation by default.
That is: pressing the letter A will focus the next element which starts with A.
Initiating a search operation requires pressing Ctrl-F or F3, like the editor.
While searching, focus is in the find input box as opposed to the list itself.
Pressing DownArrow will focus the first list element which was found.
We'll preserve all custom behavior of context keys, eg. used by the VIM extension).
In VIM, the pre-existing / command will trigger simple keyboard navigation, as opposed to opening the find widget.
The VIM extension has the option to change this behavior themselves.
And:
In general:
Keyboard navigation is now called type navigation
Filter on type is now called find mode, aligned with a new find concept
Settings
workbench.list.keyboardNavigation has been renamed to workbench.list.defaultFindMode
workbench.list.automaticKeyboardNavigation has been deleted
Commands
list.toggleKeyboardNavigation has been renamed to list.triggerTypeNavigation
list.find has been added
list.closeFind has been added
list.toggleFilterOnType has been renamed to list.toggleFindMode
Context Keys
Mainly used by the vim extension:
listSupportsKeyboardNavigation has been renamed to listSupportsTypeNavigation
listAutomaticKeyboardNavigation has been renamed to listTypeNavigationMode
"With the focus on the File Explorer start to type part of the file name you want to match.You will see a filter box in the top-right of the File Explorer showing what you have typed so far and matching file names will be highlighted."
"Hovering over the filter box and selecting Enable Filter on Type will show only matching files/folders."
documentation: https://code.visualstudio.com/docs/getstarted/userinterface#_filtering-the-document-tree