This is a quick look at how to set multiple rulers in Sublime Text 3 to help keep code readable using differing line widths to indicate soft and hard line length limits.
It’s a good idea to restrict the number of characters on a line of code to maintain readability. This basically helps us avoid having to horizontally scroll or word-wrap to be able to follow a line. Many coding standards provide a guide for line length limits. For example, the popular PHP coding standard PSR-2 suggests a soft limit of 120 characters, and recommends no more than 80 characters:-
There MUST NOT be a hard limit on line length; the soft limit MUST be 120 characters; lines SHOULD be 80 characters or less.
The wording of that could be better on the PHP-FIG website, but basically it highlights that it is a good idea to have two line length guidelines; basically with PSR-2 aim to keep lines less than 80 characters long and don’t exceed 120 characters (unless this is unavoidable). With Sublime Text we can set multiple rulers (vertical guides) to indicate these limits and help us to keep our code within the guidelines.
In our settings for Sublime Text, we can set multiple rulers like this:-
"rulers": [ 80, 120 ],
This would give us a ruler 80 characters and another at 120 characters. Two thin vertical lines will show in the editor window representing our line length limits. Now using our PSR-2 example, we shouldn’t be exceeding the second limit at 120 characters so it makes sense to make this ruler standout more. We can do this by drawing another ruler +0.1 of the ruler we’ve defined:-
"rulers": [ 80, 120, 120.1 ],
This will make the second ruler at 120 look thicker than the one at 80.
Setting rulers like this should help you keep your code readable and within any guidelines set by the coding standards you develop to.
If you have have difficulties getting the rulers to show you may need to check that you are using a monospace font (which Sublime Text uses by default), otherwise the rulers may not show.