I'm trying VS Code for a few days and I've installed csscomb extension. It works fine when I put .csscomb.json on my work directory.
But I wish it worked even on file I open outside of my work directory.
Could you tell me how to configure VS Code and/or csscomb to work like this?
I use Windows 10 Pro.
According to the csscomb page on VS Code's Marketplace...
They have "Supported settings"
csscomb.preset
Type: Object or String
Defaut: {}
Config's name. Should be one of the
following: csscomb, zen, yandex or an object containing custom
configuration or path to config.
And the following warning:
Warning!
If you want to specify a file in the current directory, the path must
begin with a ./ or ../ if relative to the current directory. Also you
can use HOME directory as ~ symbol.
In other words, since there is no default, you have to set either a preset config or path to a custom config.
To configure csscomb in VS Code:
Go to File > Preferences > Settings
Select the "User Settings" tab in the right window (to apply the config globally)
Expand the options for "CSScomb configuration"
Click the pencil to the left of "csscomb.preset"
Click "Copy to Settings"
Enter the path to your custom config or choose a preset
{
"csscomb.preset": "~/.vscode/.csscomb.json"
}
OR one of ("csscomb", "zen", "yandex")
{
"csscomb.preset": "csscomb"
}
Next, you need to create the .csscomb.json file in that location. I chose the C:\Users\username\.vscode directory because that's where VS Code also downloads extensions on Windows.
Here's the config I created using csscomb's config generator:
{
"always-semicolon": true,
"color-case": "upper",
"block-indent": " ",
"color-shorthand": true,
"element-case": "lower",
"eof-newline": false,
"leading-zero": false,
"quotes": "double",
"sort-order-fallback": "abc",
"space-before-colon": "",
"space-after-colon": " ",
"space-before-combinator": " ",
"space-after-combinator": " ",
"space-between-declarations": "\n",
"space-before-opening-brace": " ",
"space-after-opening-brace": "\n",
"space-after-selector-delimiter": " ",
"space-before-selector-delimiter": "",
"space-before-closing-brace": "\n",
"strip-spaces": true,
"tab-size": true,
"vendor-prefix-align": true
}
You can also include an option for sorting tags (or copy it from one of their presets on git):
{
"sort-order": [
[
"font",
"font-family",
"font-size",
"font-weight",
"font-style"
],
[
"position",
"z-index"
]
]
}
Now you should be able to format CSS within VS Code by typing ctrl+shift+p then typing "CSScomb" then enter.
"Formatter" extensions are supposed to be recognized by the default formatting keyboard shortcut shift+alt+f, however I haven't gotten that to work. I think it's something the developer has to configure.
Instead, you can create your own keyboard shortcut in VS Code:
Go to File > Preferences > Keyboard Shortcuts
Click the link at the top to edit keybindings.json
Add your custom keybinding
{
"key": "ctrl+shift+c",
"command": "csscomb.execute"
}
Now you should be all set!
Related
As directed by the VSCode github repo - I have an simple ask. Is it possible to set a human readable application name for a VSCode Workspace?
At the moment, my .code-workspace file looks like.
{
"folders": [
{
"name": "Some project",
"path": "../some-project"
}
]
}
Having a look through the Settings (File->Preferences->Settings) for the Workspace there is a plethora of settings. Curiously there is an appName environment variable - but surely there should be a way of customising this.
The title bar looks like the following with acme.app (Workspace):
Curiously the workspace filename is called acme.app.code-workspace.
I spotted window.title in settings when having a look earlier. You can customise it in the code-workspace. I am not sure whether this would be the best way. Would be nice if we could set an environment variable workspaceName or something and use that - if we needed to use elsewhere.
If you add the settings section - then add the window.title it will default the value to ${dirty}${activeEditorShort}${separator}${rootName}${separator}${appName}.
{
"folders": [
{
"name": "Some project",
"path": "../some-project"
}
]
"settings": {
"window.title": "${dirty}${activeEditorShort}${separator}${rootName}${separator}${appName}"
}
}
Here you can see the following:
dirty - displays an indicator of whether the current file has changed
activeEditorShort - the current file
separator - configured separator i.e. '-'
rootName - defaults to acme.app (Workspace)
appName - defaults to Visual Studio Code
So you could change the rootName to be the human-readable text:
"window.title": "${dirty}${activeEditorShort}${separator}MY SUPER PROJECT${separator}${appName}"
Which gives us:
I am trying to use VS code editor for creating kubernetes yaml files, by some reason, vscode is not showing auto-complete commands or space in my yaml files even though I have installed Yaml Support by Redhat extension and configured yaml.schema file as per below:
{
"yaml.schemas": {
"Kubernetes": "*.yaml"
}
}
Any help would be appreciated.
Thanks
I don't know why your config does not work. Here's mine:
{
"workbench.colorTheme": "Default Light+",
"workbench.startupEditor": "none",
"editor.cursorSurroundingLines": 5,
"window.zoomLevel": 3,
"redhat.telemetry.enabled": false,
"yaml.schemas": {
"Kubernetes": [
"deploy*.yaml"
],
},
}
This snippet works for me which currently selects deploy*.yaml files.
I added rest of settings just to show overall structure. Only yaml.schemas part matters, of course.
To access this file one should press command+shift+P (macOS), and type >user settings json in the search. To reload vscode one should press command+shift+P and then type >reload window there.
I tried to match *.yaml and it works as well.
Hopefully this answer will help some vscode newbie like me. It's not very obvious how to proceed with yaml configuration after initial install.
Fix This Problem On The Vscode Step by Step
Step 1 : install yaml plugin on the vscode
Step 2 : Edit this path vscode file>prefrences>settings>Extention>YAML
Step 3 : After Click Yaml on the right side find and edit YAML: Custom Tag Edit in setings.json
Step 4 : Append This lines in File Settings.json
"https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.22.4-standalone-strict/all.json": ["/*.yaml","/*.yml"]
Step 5 : Final Reload vscode You can use Ctrl+Shift+p and search Reload Window On The Vscode
try this.
{
"yaml.schemas": {
"Kubernetes": "*.yaml"
},
"redhat.telemetry.enabled": true
}
you can try it.
"yaml.schemas": {
"http://www.schemastore.org/json/composer": ["/*"],
"kubernetes": ["/*.yaml"]
},
I have a JS project with babel configuration, and it's configured to support relative paths. Instead of doing this:
import Class from '../../../../somePath/Class';
Writing the code in a more clean way:
import Class from 'app/somePath/Class';
babel.config.js
const plugins = [
[require('babel-plugin-module-resolver'), { root: ["./app/"] }],
];
That's all great, but I struggle with navigation trough files. For example when using CMD+Click on path, to navigate to file doesn't work on relative paths.
Is there a way to support navigations for relative paths in VSCode?
UPDATE
I tried the method suggested by #rioV and add HTML Related Links configuration to my project:
myapp/.vscode/settings.json
Added the following to project settings:
"html-related-links.include": {
"javascript": [
{ "find": "import [^ ]+ from '((?=app/).+?)';", "filePath": "/$1.js" },
{ "find": "import [^ ]+ from '((?!app/).+?)';", "filePath": "$1.js" }
]
},
User/settings.json
Also have included html-related-links.alwaysShow to true in the User settings:
"html-related-links.alwaysShow": true,
"html-related-links.fileroot": [
"./app"
],
And still doesn't seem to navigate when clicking the file path.
You can use the extension HTML Related Links v0.6.0. Now the name is no longer correct because it also can show related files in other file types.
If you add the following to your project/.vscode/settings.json
"html-related-links.include": {
"javascript": [
{ "find": "import [^ ]+ from '((?=src/).+?)';", "filePath": "/$1.js" },
{ "find": "import [^ ]+ from '((?!src/).+?)';", "filePath": "$1.js" }
]
}
The imports that start with src/ are treated relative to the file root folder (most likely the workspace root). If you have a different file root you also need to modify the html-related-links.fileroot setting.
The other imports (do not start with src/) are relative to the current file.
Because you use JavaScript files you also have to set html-related-links.alwaysShow to true in the User settings or the (Multi Root) Workspace settings.
In the Explorer View Container there is a view named HTML Related Links. If you click on one of the entries that file will be opened if it exists.
From VSC v1.46 you can drag/drop views to a different location
I installed the Run On Save extension for VS Code. I made a Workspace setting for it, and if I change a file then resave, it does not seem to run. "I run for all files" does not show up in the console or terminal.
When I chose to edit the command configuration in my Workspace settings, it automatically edited the file with the comment "Place your settings in this file to overwrite default and user settings." so it looks like this:
// Place your settings in this file to overwrite default and user settings.
{
"editor.mouseWheelZoom": false,
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".*",
"isAsync": true,
"cmd": "echo 'I run for all files'"
}
]
}
}
I'm new to configuring Workspace settings, so I'm not sure if this is okay or not. I ensured that Run On Save is enabled by selecting it on the command palette.
Here is the site for the extension: https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave
In order to see the console output, you have to be in the Output tab and select the Run On Save option in the dropdown. The extension was created before the integrated terminal existed and hasn't seen a major update in a while.
Regarding the comment that was added to your config:
// Place your settings in this file to overwrite default and user
settings.
is unrelated to this particular extension. It is just vscode letting you know the purpose of the workspace level configuration. It allows you to override a subset of your more global user / default settings. This allows you to keep reasonable default preferences but to customize certain specific things in any given workspace.
Regarding the original RunOnSave extension, feel free to file an issue here https://github.com/emeraldwalk/vscode-runonsave/issues if you have any questions or problems. I would also welcome pull requests if anyone is interested.
I had the exact same issue. I removed that extension and am using this one instead:
https://marketplace.visualstudio.com/items?itemName=wk-j.save-and-run
It is a fork based on RunOnSave. This one works for me when I set its configuration in my user settings and then run the command "Save and Run: Enable".
This one uses the bulit-in powershell terminal.
HTH
In addition to our dear #bingles, I have accidentally discovered that the commands should be added to .vscode/settings.json file instead of .vscode/emeraldwalk.runonsave as said in the plugin documentation
Add it to settings.json and everything should work as expected.
For the extension to work on Workspace you must put the emeraldwalk.runonsave inside settings:
{
"settings": {
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".*",
"isAsync": true,
"cmd": "echo 'I run for all files'"
}
]
}
}
}
A related one:
Previously I used RunOnSave, this time around I used Code Runner.
Code Runner - https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner
Below are it's settings I used:
File: %AppData%\Code\User\keybindings.json
{
{
"key": "ctrl+s",
"command": "code-runner.run"
}
}
File: .vscode\settings.json
{
"code-runner.saveFileBeforeRun": true,
"editor.codeActionsOnSave": [
"code-runner.executorMap"
]
"code-runner.executorMap": {
"javascript": "node a.js"
},
}
If possible, you could use Code Runner with the above settings, or use a similar to the above settings for the RunOnSave.
Note that RunOnSave has its own tab which is time-consuming to switch to another tab.
With Code Runner I can see the output in the Output tab itself which is a very nice thing, saves time.
I'm trying to create a custom package and one thing I would like to do is bring up the Build Systems(located in the Tools menu item) in the command palette(show_overlay). So I have tried to create a Default.sublime-commands file in my package and type in...
[
{ "caption": "Build System", "command": "build_system" }
]
...to enable that menu item for the command palette(I also tried set_build_system) and then I created a Default.sublime-keymap file in my package so that I can access the Build System list from via shortcut...
[
{
"keys": ["f9"], "command": "show_overlay",
"args": {"overlay": "command_palette", "text": "Build System"}
}
]
I am not having any luck exposing the Build System menu item to the command palette. Can I get some help on this? I also noticed the Tools menu item is not available in the command palette as well. What am I missing?
Ok I figured it out. The command palette can only be populated by existing commands that run in sublime. The way you can view which commands that are being run in sublime is to open up the console(CTR + ~) and type in sublime.log_command(True)
Now whenever you do anything that makes sublime trigger a command, it will log that action in the console. Armed with this knowledge, we we go to Tools > Build System and click on the build system type we want, say, C++, we get:
command: set_build_system {"file": "Packages/C++/C++.sublime-build"}
Sweet! Knowing this we can go to our .sublime-commands file(you can call it Default.sublime-commands) and type in the below code:
[
{
"caption": "Set Build System: C++", "command": "set_build_system",
"args": { "file":"Packages/C++/C++.sublime-build" }
}
]
Tip: pay close attention to the "caption" it's what we will use to tie our .sublime-command file with our .sublime-keymap file. Let's add another one build system:
[
{
"caption": "Set Build System: C++", "command": "set_build_system",
"args": { "file":"Packages/C++/C++.sublime-build" }
},
{
"caption": "Set Build System: Python", "command": "set_build_system",
"args": { "file":"Packages/Python/Python.sublime-build" }
}
]
Now that we have exposed these two commands in our .sublime-commands file. We can create a shortcut for it in our .sublime-keymap file. I called mine Default.sublime-keymap:
[
{
"keys": ["f8"], "command": "show_overlay",
"args": {"overlay": "command_palette", "text": "Set Build System:"}
}
]
Notice the "text" key. Look familiar? This is how you connect your key binding to your command. Save press F8 and boom! You have our own custom command palette menu. Enjoy!
PS: you can put your .sublime-commands/.sublime-keymap files in your User package or add to any existing ones if you have them there if you just want to customize your sublime text 2 without making a custom package.