292

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.

ragnarswanson
  • 258
  • 3
  • 9
Denis Óbukhov
  • 4,069
  • 4
  • 17
  • 27

7 Answers7

712

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.

Community
  • 1
  • 1
Ross Allen
  • 40,801
  • 12
  • 92
  • 89
  • 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. – commadelimited Sep 26 '12 at 14:09
  • @commadelimited The ruler changes color for me based on the background color of the theme I select. Is your settings file being used? Try changing another setting like "tab_size" or "font_size" to check. – Ross Allen Sep 27 '12 at 16:42
  • 1
    @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. – commadelimited Oct 02 '12 at 15:49
  • I'm having the same issue as @commadelimited. I'm at a loss as to why this is. – TicViking Apr 23 '13 at 04:17
  • @TicViking Make sure your settings file is a hash: the settings should be wrapped in curly brackets like {"rulers": [80]}. If that doesn't change things, try changing your color scheme. Maybe the ruler color is the same as the background color in your current color scheme. – Ross Allen Apr 23 '13 at 04:20
  • 1
    @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 :) – TicViking Apr 28 '13 at 22:11
  • 1
    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 – RogueDeus Jul 24 '16 at 20:27
  • Is there a way to specify rulers for specific filetypes or at least only for selected open files? – rodripf Aug 02 '16 at 17:16
  • 1
    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 – Kamikaze Rusher Aug 18 '16 at 21:07
  • I had to close and reopen the file for this to work (closing and reopening the ST2 project alone wasn't enough). – Samuel Nov 16 '16 at 14:52
  • @denis-óbukhov consider making this the accepted answer? This is so much better explanation and correct (one shouldn't edit default settings) answer. – joonas.fi Mar 08 '17 at 10:42
  • To access my "User Settings" I had to edit this file (Packages/User/Preferences.sublime-settings) in my preferences drop down . I didn't have a 'Settings- User' option. – Rebecca Sich Feb 26 '19 at 21:31
117

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.

Robert Jones
  • 1,358
  • 1
  • 9
  • 4
  • 156
    Keep scrolling for a more detailed answer by @ssorallen. – Don Spaulding Mar 25 '13 at 15:56
  • 21
    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. – Olivier Lacan Feb 17 '14 at 07:54
51

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.

Ross Allen
  • 40,801
  • 12
  • 92
  • 89
Tecnocat
  • 1,073
  • 1
  • 11
  • 14
  • 2
    That's a good point. I updated my answer to suggest editing user settings rather than the defaults. – Ross Allen Aug 06 '12 at 07:39
  • 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. – Fred Dec 27 '16 at 18:04
8

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.

Michael Ruth
  • 1,314
  • 11
  • 17
  • 2
    Worth mentioning that there may not be a `"rulers"` entry in `Preferences -> Settings-User`. In that case, you'll have to create one. – Tass Apr 04 '16 at 14:06
  • The font_face needs to be Monospace. After setting that it worked for me. Thanks for the answer. – Nikhil Goyal Mar 20 '21 at 11:34
1

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:

  1. Install PackageControl
  2. Open PackageControll (e.g. via ⌘ + SHIFT + P)
  3. Type "Install" and select "Package Control: Install Package"
  4. 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")

Community
  • 1
  • 1
romellem
  • 3,144
  • 1
  • 22
  • 50
0

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

German Khokhlov
  • 909
  • 9
  • 13
  • Same here, changed to `"font_face": "Input"` and `"rulers": [80]` disappeared from my config file. Looks like ST3 bug. – Marek Ka. Oct 22 '14 at 09:47
0

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)

ctlockey
  • 333
  • 3
  • 12