Vertical rulers in Visual Studio Code - visual-studio-code
Rendering More than One Ruler in VS Code
VS Code's default configuration for a ruler is demonstrated below.
"editor.ruler": 80
The issue I am having with the default VS Code configuration (as shown above) is that it only renders a single ruler. In the Sublime Text Editor I can render as many rulers as I like using the following Sublime configuration.
"rulers": [72, 80, 100, 120]
Is it possible to render multiple rulers in V.S. Code. If it is possible, What does a multi-ruler configuration look like in VS Code?
Visual Studio Code 0.10.10 introduced this feature. To configure it, go to menu File → Preferences → Settings and add this to to your user or workspace settings:
"editor.rulers": [80,120]
The color of the rulers can be customized like this:
"workbench.colorCustomizations": {
"editorRuler.foreground": "#ff4081"
}
In addition to global "editor.rulers" setting, it's also possible to set this on a per-language level.
For example, style guides for Python projects often specify either 79 or 120 characters vs. Git commit messages should be no longer than 50 characters.
So in your settings.json, you'd put:
"[git-commit]": {"editor.rulers": [50]},
"[python]": {
"editor.rulers": [
79,
120
]
}
With Visual Studio Code 1.27.2:
When I go to File > Preference > Settings, I get the following tab
I type rulers in Search settings and I get the following list of settings
Clicking on the first Edit in settings.json, I can edit the user settings
Clicking on the pen icon that appears to the left of the setting in Default user settings I can copy it on the user settings and edit it
With Visual Studio Code 1.38.1, the screenshot shown on the third point changes to the following one.
The panel for selecting the default user setting values isn't shown anymore.
In v1.43 is the ability to separately color the vertical rulers.
See issue Support multiple rulers with different colors - (in settings.json):
"editor.rulers": [
{
"column": 80,
"color": "#ff00FF"
},
100, // <- a ruler in the default color or as customized (with "editorRuler.foreground") at column 100
{
"column": 120,
"color": "#ff0000"
},
]
To change the default color for a ruler:
"workbench.colorCustomizations": {
"editorRuler.foreground": "#fffa"
// or "#ffffffaa" - the a's are alpha transparency values
}
Visual Studio Code: Version 1.14.2 (1.14.2)
Press Shift + Command + P to open palette
For non-macOS users, press Ctrl+P
Enter "settings.json" to open setting files.
At default setting, you can see this:
// Columns at which to show vertical rulers
"editor.rulers": [],
This means the empty array won't show the vertical rulers.
At right window "user setting", add the following:
"editor.rulers": [140]
Save the file, and you will see the rulers.
To expand on the above, you can set multiple rulers and colors for each ruler. The default color appears to be "#5a5a5a", and if you tack on two additional digits to the end you can adjust its transparency to make some rulers more faint than others.
Here are my rulers, defined in a concise manner that's easier to edit.
"editor.rulers": [
{"column": 0, "color": "#5a5a5a80"}, // left boundary is 50% opaque
{"column": 2, "color": "#5a5a5a20"}, // tab stops are 12.5% opaque
{"column": 4, "color": "#5a5a5a20"},
{"column": 6, "color": "#5a5a5a20"},
{"column": 8, "color": "#5a5a5a20"},
{"column": 10, "color": "#5a5a5a20"},
{"column": 40, "color": "#5a5a5a20"}, // center line
{"column": 79, "color": "#5a5a5a20"}, // right rule minus one
{"column": 80, "color": "#5a5a5a80"}, // right rule
{"column": 120, "color": "#5a5a5a40"} // extra right rule
],
Customizing VS Code's Char-len Ruler:
The following answer is far more recent than the other answers provided for this question, therefore; it is important to note that this answer contains information & content not provided by any of the other answers. I have formatted the question below into 4 configurations. Each configuration builds on top of the last configuration, consequently; The first configuration is simple, and offers a simple result, whereas the last configuration is more complex and offers much more.
For your convenience, I have included images at the bottom of each configuration's example. The images allow you to view a configuration, then see the result that the configuration has. This is important, because without the images you would have to bounce back and forth between here & your editor to see what each configuration looks like.
Config #1 | The Obvious Single Ruler Config
The obvious setting is the setting that has been suggested many times over. I will mention it here, just because it is the correct place to start.
Add the following JSON Property to your settings.json file.
{
"editor.rulers": [80]
}
PLEASE NOTE! It may be required that you reload the instance of VS Code (semantically speaking: some refer to this as reloading the window) being configured to get the newly added configuration to render as expected. (to see how to reload your window quickly, scroll to the end of this answer).
Once the configuration takes, your editor should look like this:
Config #2 | Multiple Rulers
Obviously the ruler takes an array as its assigned value. The array allows VSC users to add multiple rulers.
Be simply adding one value to the configuration in the last example (as shown in the snippet below) we can add another ruler.
{
"editor.rulers": [80, 125]
}
The screen shot I took is a bit short, but it communicates the point well enough. You can see that there are now two vertical lines, rather than a single line. Many front-end developers opt for this configuration because 125 is often used as the preferred line-length for HTML, and 80 is the preferred line-length for JavaScript embedded in HTML documents.
Config #3 | Coloring the Ruler
This configuration demonstrates the whimsy side of playing with VS Code's configuration; and the ruler is certainly one of the more whimsical editor-features that VS Code ships with. This configuration shows you how to color the configuration we used above. To be able to custom color the rulers, it is required that an additional setting be added to the configuration, take a look below:
{
"workbench.colorCustomizations": {
"editor-ruler.foreground": "#0099AA"
},
"editor.rulers": [80, 125]
}
Below you can see the awesomeness of the pacific blue color!
Config #4 | Coloring the Ruler so it works w/ Code
So, as awesome as beautiful pacific-blue rulers are, they are not always practical. The opaque — and in this case highly contrasted — rulers streak right behind are code which can greatly decrease the readability of your code. For this very reason, developers generally opt for a configuration that places a single ruler at the desired line length, however, there is another way. By adjusting the previous configuration ever so slightly, we can render the rulers in a way that is much less intrusive. Take a look at the configuration below.
Do you see the subtle change?
{
"workbench.colorCustomizations": {
"editor-ruler.foreground": "#0099AA33"
},
"editor.rulers": [80, 125]
}
Below demonstrates where the change was made:
Color used in the 3rd configuration:
"editor-ruler.foreground": "#0099AA"
Color used in the 4th configuration:
"editor-ruler.foreground": "#0099AA33"
The new configuration's adjusted chromatic value (the color/hue) renders transparently (or not at 100% opacity), in-other-words; the rulers are rendered to be partially transparent (approximately 25% transparency).
The change has a rather significant effect because opaque rulers hinder readability, and can distract the programmer from her code. A programmer may opt for transparent rulers because transparent rulers will allow her to measure the length of her code at any length intervals she chooses, without hindering the readability of the code.
See the transparent rulers below? You might want to click on the image to see the larger view.
Config #5 | The Ultimate Customized Ruler
The problem with transparent rulers is that they are not quite as fancy as the other rulers, fortunately, there's a way to get the best of both worlds. This example uses two images (or screen-shots): One image that shows the configuration, just like the other images you have been viewing above, and the other is a final image showing the configuration I use. The configuration I use is shown as a way to help put into perspective what you're able to accomplish with a good ruler configuration.
Below is a crazy sort of configuration...
{
"workbench.colorCustomizations": {
"editorRuler.foreground": "#00999922"
},
"editor.rulers": [
20, 40, 40, 60, 60, 60, 60, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80
]
}
I KNOW CRAZY RIGHT?!
This configuration, looks nutter-butter, but it actually produces a very interesting, and highly customized sort of result. I really like this example because it offers a great demonstration of how the ruler array-property configuration works, and what can be accomplished with it.
Here is the result:
Notice what is happening?
Each ruler is brighter than the last. The rulers are doing this because we are laying several transparent rulers over each other. With ever layer the rulers color becomes more saturated. This is an extremely fun effect to play with.
Like I said above, I will show you I use this effect to configure my environment:
Note that I make all of the rulers very transparent except for the last two. This offers a snazy environment, while still keeping things practical. Having several rulers also helps me to format and organize my code. I am so use to having them now that I can hardly stand to work in an environment without them.
If I work on a project with a style-guide that enforces an 80 character limit, I often will place one line at 80, and another at 90. I write my code such that it breaks before, or at, 80 chars, however I don't like the 80 char limit personally, I feel that the standard should be 85 - 90 chars. 80 really makes developers feel like there pushed into a box. So if I don't like the way a line looks at 80, I will extend it to 90. Before I commit, I look at the file and I can quickly see everywhere I went over 80, I add line-breaks, the commit. then I use ctrl+z to reset the line breaks so the extend past 80.
Another purpose, Is when I comment, I prefer to end my comments at 70, it helps me visually distinguish between comments and code. When you have the extra lines, there is a good chance you'll start using them to do all sorts of your own little formatting customs.
The resource below only pertains to those who are in need of instruction on reloading there instance of VS Code.
RELOADING YOUR WINDOW IN VS CODE
To reload your window, press F1 to open the Quick-input Menu. You should see the menu drop open, type Developer: Reload Window, then select the Developer: Reload Window option from the drop-down menu.
File -> Preferences -> Settings Or cntrl+,
type "rulers" and click Edit Setings.json
3. Add the size value by ',' As you wish
Like this(Gif)
Combining the answers of kiamlaluno and Mark, along with formatOnSave to autointent code for Python:
{
"editor.formatOnSave": true,
"editor.autoIndent": "advanced",
"editor.detectIndentation": true,
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"editor.formatOnPaste": true,
"editor.multiCursorModifier": "ctrlCmd",
"editor.snippetSuggestions": "top",
"editor.rulers": [
{
"column": 79,
"color": "#424142"
},
100, // <- a ruler in the default color or as customized at column 0
{
"column": 120,
"color": "#ff0000"
},
],
}
Go to Menu File -> Preferences -> Settings and add
"editor.rulers": [preferred-value, preferred-value]
The color can be customized in
workbench.colorCustomizations
I like this explanation. It also tells how to set different colors for more than one ruler.
if you're using Flutter then you need to edit the ruler for dart, you'll navigate to the file from RUN command:
%APPDATA%\code\User\settings.json
and set the ruler to 0
like in the picture.settings.json
Related
How to disable colorized brackets?
When I use VS Code I equip either a light, or dark theme, depending on the time of day, and the lighting in the room. The problem is when I equip a light theme, the I posted an image of what my editor looks like with my light theme equipped to demonstrate the issue. I tried BracketPairColorization.enable: "false" as shown in the very bottom image, but it does not work. Is there a way I can disable the theme-properties that color the bracket-pairs, or setting for disabling the colorized-bracket pairs that works? I have inspected every settings, and even tried the obvious, as demonstrated in the image below, and figuring out how to turn off the bracketPairColorization feature still eludes me. How do you completely disable the Colorized Brackets?
VS Code has enabled the Bracket pair Colorization feature by default. This has caused many people to seek out a way to disable the feature, however there is a bit more to the story than simply using: "editor.bracketPairColorization.enabled": false, that is because there are 2 different block guide features that have been built-into the bracketPairColorization feature, as well as an indent-guide feature that highlights much the same way. To disable all the bracket pair colorization & guides, you need to do the following. { // Bracket-pair colorization "editor.bracketPairColorization.enabled": false, // Bracket-pair guides "editor.guides.bracketPairsHorizontal": false, "editor.guides.highlightActiveBracketPair": false, // Indentation guides "editor.guides.indentation": false, "editor.guides.highlightActiveIndentation": false } TO LEARN HOW TO DISABLE ONLY PARTS OF THE FEATURE, OR MORE IN GENERAL ABOUT THIS FEATURE, REFER TO THE FOLLOWING SECTIONS Intro Disabling/Configuring Bracket Pair Colorization & Guides V.S. Code's 'Bracket-pairs Colorization' feature frustrates many developers. Recently it was activated by default, and people were upset about it. The problem wasn't the actual feature itself, but the fact that the feature has an enable/disable setting that doesn't seem to turn the feature off when it is set to disable the feature. If you have tried to turn this feature off, and wound up unable to, do think get mad, or upset at yourself (which is what I do in similar situations), most have went through the same hardship, furthermore; this feature doesn't limit its "frustrating of users" to only those who desire to disable it altogether, the truth is, the feature is highly customizable, it actually includes about 3 different features wrapped into one, and is hard to make sense off for anyone attempting to configure it for the first time. The best way to do this is going to be to demonstrate the configuration that you use to completely disable the feature. Then, after that I will walk you through each setting, and explain what it is they do, and the theme properties they are attached too. Part-2 Disabling Bracket-pair Colorization & Bracket-pair Guides Below is a "tried -&- true" method for the complete disablement of the bracketPairColorization, bracketPairColorization.guides & guides.indentation editor-features (or perhaps it would be better to type "editor.* features"). { // Bracket-pair Highlighting "editor.bracketPairColorization.enabled": false, // Bracket-pair guides "editor.guides.bracketPairsHorizontal": false, "editor.guides.highlightActiveBracketPair": false, // Indentation guides "editor.guides.indentation": false, "editor.guides.highlightActiveIndentation": false } Part-3 Disabling Parts of Bracket-pair Colorization If there are parts of the feature that really chap your hide, but other parts that you like, you can specify the certain rendering, coloring, and "onActive"-highlighting of Bracket-pairs, and the indent guides (horizontal &/or vertical), using the configurations shown below. (3a) Taking Advantage of the Colorized Bracket-pairs Setting In truth, I feel the complexity of the configuration required for this feature is 100% justified by what you can do with it. Though I don't agree with it being activated by default. Below is a demonstration of what can be done with Bracket-pair Colorization that makes it so awesome. As you can see, the setting "editor.language.colorizedBracketPairs": [ ... ] is being configured in the snippet below. The array pairs bellow are the bracket-pairs that the feature will highlight. In other words, this is how to define which bracket-pairs are highlighted. One way to disable the coloring of bracket pairs, is by simply not assigning any pairs to the colorizedBracketPairs setting. You can define everything from a functions braces, to markdown astriks ["***", "***"], to C Pre-processor directives. The world is your ostyer when it comes to this setting. "editor.language.colorizedBracketPairs": [ ["{", "}"], // Block-Scoped Braces/Function-Braces ["[", "]"], // Array Square-brackets ["(", ")"], // Func Call-args/Declaration-params Brackets ["<", ">"], // HTML/XML Tags ["\"", "\""], // String Quotations ["_", "_"], // Markdown: Italicized ["**", "**"], // Markdown: Bold ["**_", "_**"], // Markdown: Italicized & Bold ["{{", "}}"], // Double Curly Brackets ["`", "`"], // Back-tics ["#ifndef", "#endif"], // Highlight C Directives as pairs ["<%", "%>"], // Wrapping variables in JSON ["${", "}"], // Wrapping template variables in JS/TS ["$(", ")"] // Wrapping of template variables in BASH ] (3b) Customizing Indentation Guides You can also customize "Bracket-pair Colorization Guides" & "Indent Guides" by asigning values other than true/false where applicable. For example: FOR EXAMPLE: The two settings below, can be configured using a third, boolean-alternate value: The configuration below, configures the "bracket pair guides" to highlight only the active guides for the active block and no other guides. "editor.guides.bracketPairs": "active", "editor.guides.bracketPairsHorizontal": "active", Now, if you how the setting below configured to true, it won't do anything, if bracketPairs are also active at the same time. "editor.guides.highlightActiveIndentation": false, the editor.guides.highlightActiveIndentation setting in the snippet above, is part of a pair of settings used to customize a feature that was part of VS Code long before bracketPairs were around. NOTE: If you have the settings below set to true, and if you have "editor.guides.bracketPairs" set to true as well, and over-highlighted editor is the end result. You will see indent guides highlighting at different levels, as the bracket pairs work differently than the indent guides. The bracket-pair guides try to highlight use language-defined blocks, while the indent guides use the value assigned to "tab.width": number? to determine where it will highlight. This causes indentation to be highlighted twice in many situations. "editor.guides.indentation": true, "editor.guides.highlightActiveIndentation": true, For some reason they made a setting that helps you configure the two at once, I don't suggest it, but it's the value "always" assigned to "highlightActiveIndentation". If you did want to turn them on with bracket pairs, below shows how you would do it. "editor.guides.bracketPairs": "active", "editor.guides.bracketPairsHorizontal": "active", "editor.guides.indentation": true, "editor.guides.highlightActiveIndentation": "always", Another option you have is you can set the "Bracket-pair guides" to true, then configure them to highlight the active block, like this: "editor.guides.bracketPairs": true, "editor.guides.bracketPairsHorizontal": true, "editor.guides.highlightActiveBracketPair": true, Part-4 Associated Theme Colors So if we look at the last snippet, just above (I'll post it again below)... "editor.guides.bracketPairs": true, "editor.guides.bracketPairsHorizontal": true, "editor.guides.highlightActiveBracketPair": true, ...you can see that all bracket pairs are turned on (so they are colored), but the active ones are highlighted. The way that this works is that in a theme, or in your settings.json file, using the "workbench.colorCustomizations": {}, setting, the standard coloring of the bracket-pairs are colored a different color at 6 different block (or scope) levels. The color properties to which those colors are assigned are shown below: "editorBracketPairGuide.background1": "#CC1177", "editorBracketPairGuide.background2": "#5544DD", "editorBracketPairGuide.background3": "#CC6622", "editorBracketPairGuide.background4": "#779428", "editorBracketPairGuide.background5": "#009944", "editorBracketPairGuide.background6": "#1155DD", Now, if you have highlightActiveBracketPair set to true, then the block you focus on is brighter, or a different color (it depends on how the properties below are configured), the active bracketPairGuide is colored using these theme-properties: "editorBracketPairGuide.activeBackground1": "#EE2288", "editorBracketPairGuide.activeBackground2": "#8844FF", "editorBracketPairGuide.activeBackground3": "#FF5C0C", "editorBracketPairGuide.activeBackground4": "#99CC33", "editorBracketPairGuide.activeBackground5": "#00CC88", "editorBracketPairGuide.activeBackground6": "#0077FF", And the actual bracket-pairs (or the actual brackets themselves) are colored using these properties: "editorBracketHighlight.foreground1": "#CC1177", "editorBracketHighlight.foreground2": "#5544DD", "editorBracketHighlight.foreground3": "#CC6622", "editorBracketHighlight.foreground4": "#779428", "editorBracketHighlight.foreground5": "#009944", "editorBracketHighlight.foreground6": "#1155DD", "editorBracketHighlight.unexpectedBracket.foreground": "#DD100C", For more information visit: https://code.visualstudio.com/blogs/2021/09/29/bracket-pair-colorization -&/or- https://code.visualstudio.com/updates/v1_60#_high-performance-bracket-pair-colorization
TL;DR You can remove this feature by adding the following to the settings.json file. shortcut: (type ctrl+shift+p, click on Open Settings (JSON)) "editor.language.colorizedBracketPairs": [] or, if you'd like to set specific brackets you can pass them into the array "editor.language.colorizedBracketPairs": [ ["{", "}"], ...]
How to highlight current line number in Visual Studio Code / VS Code
I am in the process of migrating from Atom to VS Code, as it seems to be what all the cool kids use these days. In atom I was able to highlight the current line number as pictured (the blue highlight in the gutter). Is there a way to do this in VS Code? With a setting or extension? Can't find a way to do it, and really missing that obvious at-a-glance indication of where I'm working. (I know that I can add a background to the current line itself, but this is too intrusive to the code, especially working with a variety of languages in different colours.) Thanks!
You could try "editor.renderLineHighlight": "gutter" UPDATE In an ideal world I'd want both the gutter and the line itself highlighted, but in 2 very different colours - sadly that one doesn't seem possible, but this option is better than nothing! Well, you may try something like settings below, liner number in different color as well as box for the line "editor.renderLineHighlight": "all", "workbench.colorCustomizations": { "editor.lineHighlightBackground": "#00000000", "editor.lineHighlightBorder": "#0000ff" }
To address dark and light themes In the settings.json file add something like: "workbench.colorCustomizations": { "[Default Dark+]": { "editor.lineHighlightBackground": "#00000071", }, "[Default Light+]": { "editor.lineHighlightBackground": "#0000003f", } },
Change (or add) background color in VS Code when renaming from Explorer
In the image below I'm actually in "rename" and I'm highlighting something but there's no highlight. You'll notice there's no cursor as well because it's highlighting. This is driving me a bit bonkers because I'm either counting how many left/right arrow keys I'm moving and such to know where I am. I tried the following colors but none of these seem to do anything (in the Explorer): "workbench.colorCustomizations": { "editorRuler.foreground": "#fc199a22", "editor.selectionBackground": "#ab3beb3f", "editor.selectionHighlightBackground": "#136460e3", "editor.findMatchBackground": "#00cc44a8", "editor.findMatchHighlightBackground": "#d0ff004d", "scrollbarSlider.background": "#FC199A2c" }, I tried inspecting the element in the developer console in VS Code but the rename closes when it blurs out of the field which I need to do to select the element to know what the CSS class is to style it. I didn't see a "rename" or highlight color for the explorer here either: https://code.visualstudio.com/api/references/theme-color#editor-colors Any help would be super appreciated.
You can use the following property: "selection.background" : "#FF0" The background color of text selections in the workbench (e.g. for input fields or text areas). Note that this does not apply to selections within the editor. A caveat to this approach is that it is applied globally, not just the explorer view
In VsCode, how do I get rid of the air to the right of the text?
I cannot use the full width of the panel in VsCode. As can be seen in the picture it is quite a lot of space I can't use. (the red line) Which setting should I change? I do not have that many extensions and I have not played around very much in the settings either. (I set up a new machine every 30 och 90 days and hence don't fiddle around too much.) Here are my relevant settings: "editor.lineNumbers": "off", "editor.wordWrapColumn": 100, "editor.wordWrap": "on", "editor.minimap.enabled": false, The word wrap is at 80 characters which also happens to be the standard editor.wordWrapColumn but I am not using it but have editor.ordWrap set to on. (on means word wrap but not at a special column count) I have set editor.wordWrapColumn to another value but, as supposed, nothing changes as long as I have etidor.wordWrap set to on. I have played with setting editor.wordWrapColumn to, say, 100 and editor.wordWrap to wordWrapColumn which, as supposed, makes the lines break at 100. Setting it back and everything goes back to (ab)normal.
That is just space so your lines can grow longer. Basically to remove it resize your window to the desired space. (In case you mean the minimap just go into settings and disable it)
how to disable word-wrap in VS Code for a specific file?
I am using windows and VS Code, I have few files that I do not need to wrap them wherever I press Alt+Shift+F, is there a way to disable auto format wrapping for specific files?
Explained here Language-specific editor settings but specifically: CTRL+SHIFT+P and type "Preferences: Configure Language Specific Settings" Select the language or add section in the file (start typing [ to see list of suggestions) or edit if already there. If wrapping, depending on columns available in your editor you might want to update editor.wordWrapColumn. Lines will wrap at the minimum of viewport and editor.wordWrapColumn Example: ... "editor.wordWrapColumn": 200, "[typescript]": { "editor.tabSize": 2, "editor.wordWrap": "off", }, "[plaintext]": { "editor.wordWrap": "bounded", }, ...
Looks like VSCode allows for this. You can tweak it as you prefer for each file type. However note that there have been reports of it not working for markdown files. I guess it is something still being tweaked.
Looks like this person made an extension that might be useful for you. https://marketplace.visualstudio.com/items?itemName=Ho-Wan.setting-toggle Looks like you can setup a few quick easy setting toggles. would at least make it quicker as you're bouncing from file to file.