ChatGPT解决这个技术问题 Extra ChatGPT

How to make ruler always be shown in Sublime text 2?

I use Sublime Text 2 and want a Ruler to be shown in every file with specific line-height. But I have to show it manually in every file.


C
Community

Go to Sublime Text > Preferences > Settings - User

Add a "rulers" setting with the lines you want for the ruler:

// Adds a single vertical ruler at column 80
"rulers": [80],

If you want multiple rulers, separate the values with a comma:

// Adds two vertical rulers: one at column 80 and one at column 120
"rulers": [80, 120],

Rulers not showing? Rulers are only shown when using a monospace font, which is the default font for Sublime Text. Ensure you are using a monospace font if the settings above don't work for you.


This didn't work for me. I even tried restarting it but nothing. Does it depend on the theme you're using? I have a light colored theme with white as the background.
@ssorallen Settings -> User file is def being used. My rulers property: "rulers": [80,120] but no rulers are being shown at those column widths. Randomly I do have a ruler at 160 but I can't find that in default or user settings.
@ssorallen Done both of those. The "rulers" from tab indents show up, but not the ones from my end of line. It's strange because it's showing up with my config file on windows but not on mac.:/ Thanks for the help debugging though :)
I had exactly the same issue and managed to fix it by deleting the user preferences file in the AppData folder for sublime text. .../Packages/User
Wanted to pitch in and say that this still works on Sublime Text 3. You'll first want to disable any rulers you've currently set on any open tabs because they will override the user settings (just for that tab). Once you save the user settings, all open tabs will display the ruler
R
Robert Jones

Edit the "rulers" value in the default settings to contain the column number you want the ruler to be displayed on, and it will persist.


Keep scrolling for a more detailed answer by @ssorallen.
Actually, you shouldn't edit the Default settings. They're defaults for a reason and need to be overridden by your User settings instead, as explained in @ssorallen's answer. Changing the default settings means your rulers will disappear the next time you update Sublime, and you definitely won't enjoy that.
R
Ross Allen

Never edit Settings - Default; edit Settings - User instead. If you upgrade your SublimeText version you will lose all of your settings because Settings - Default will be overwritten.

In the Packages folders the 'User/' folder will be ignored between upgrades of SublimeText, the settings here will be persistent.

To enable the persistent rulers in any document, add the settings in Defaults - User:

{
  "rulers": [75, 80, 85]
}

This example will display 3 rulers, at 75, 80 and 85 chars length.


That's a good point. I updated my answer to suggest editing user settings rather than the defaults.
There are also syntax-specific settings, which is useful for showing a ruler in one language (say Python, where PEP8 demands 79 characters per line), but not in every other language as well.
M
Michael Ruth

As others have stated before me, select Preferences -> Settings-User and change

"rulers": [],

to

"rulers": [80],

in order to display one ruler at column 80.

Now for the rub, it seems that one must use a monospaced font in order to display rulers so you'll also need to change

"font_face": "",

to

"font_face": "Monospace",

or any other monospaced font.

Thinking about it, this makes sense. If different characters have different widths, then the ruler could potentially not be a single line, but a bunch of annoying line segments. I noticed this while using the default font and my column numbers were not the same for the same vertical position. At the same time, my fancy ruler was specified but not displayed. Changing the font to Monospace solved both problems.


Worth mentioning that there may not be a "rulers" entry in Preferences -> Settings-User. In that case, you'll have to create one.
The font_face needs to be Monospace. After setting that it worked for me. Thanks for the answer.
C
Community

While the answer by Ross Allen is great, it isn't the most convenient if you find yourself wanting to toggle the rulers on and off or change the width at various points while using Sublime.

Luckily, someone made a Package that allows you to do this.

https://packagecontrol.io/packages/QuickRulers

The package works in both Sublime Text 2 and 3.

Install Instructions:

Install PackageControl Open PackageControll (e.g. via ⌘ + SHIFT + P) Type "Install" and select "Package Control: Install Package" Type "QuickRulers" and hit Enter to install the QuickRulers package.

You can access the command (quick_rulers) through several different means, but by default it is loaded in Omnisearch via "QuickRulers: Open Panel". (i.e., Hit ⌘ + SHIFT + P and type "QuickRulers: Open Panel")


G
German Khokhlov

If you change font, ruler will not be displayed. E.g. I set "font_face": "Lucida Grande", and ruler disappeared.


Same here, changed to "font_face": "Input" and "rulers": [80] disappeared from my config file. Looks like ST3 bug.
c
ctlockey

I just had this problem and noticed that the my ruler was only showing up when I was slightly scrolled to the right horizontally. Turns out the reason it was disappearing was because I was slightly zoomed in. Press Cmd+0 to make sure you are zoomed to the default 100% size before trying other things in case this is also your issue.

(I am using Sublime Text 3)