When typing on a keyboard, you press the spacebar to separate the words from each other, by adding a bit of space between the words. Just like visible characters like a, b, c, and d, whenever you press the spacebar, a character is inserted as well, as there is no such thing in a text-input field that is plainly just a space. The only difference is that this character is invisible (or hidden), and is called a “whitespace“, which fakes the functionality of a real-world space (like when you write with your pen on a real notebook).
Whitepaces are not the only form of hidden characters used in computer inputs. Even pressing the Enter key inserts a hidden character called a EOL (End of Line). While writing code inside a text editor, a programmer might choose to view these hidden characters in order to avoid syntax errors in sensitive languages which does not ignore whitespaces and other special characters by default.
When using the Sublime Text code editor, you should’ve noticed that the whitespace characters are automatically shown when you drag and select a portion of the text. However, if you want to view these whitespace characters (as well as some others like the Carriage Return and Tabs) anytime you wish without needing to select them, this article will be the only guide you need!
Show Whitspace characters
The easiest one to show among the many hidden characters is the whitespace, here in Sublime Text. In fact, they have a dedicated setting to either view it all the time, show it only on the selected portion, or turn it off entirely. Of the 3 possible setting values, it is set to “selection”, by default. To make whitespaces visible all the time, these are the steps you’d need to follow:
After launching Sublime Text, head to the Preferences > Settings:
Inside the Preferences.sublime-settings JSON files that opened, Insert the following piece of text on the right pane of the two that got opened in the editor:
As always, make sure to save the file. You should now be able to see all the whitespaces when you open up a file in Sublime Text, without having to select them.
Show Tab Insertions
You don’t need a new setting to be enabled for viewing tab insertions in Sublime Text. Because tabs are also viewed as part of the whitespaces setting you just enabled. That is, if you set the “draw_white_space” option to “all”, then it’ll show both the whitespaces and the tab insertions in your file. The tab insertions are viewed as long lines. Here’s a quick demo:
Show Line Endings
If you’d like to view other special characters like EOL, unfortunately, it’s not possible with Sublime Text by default. However, it is possible to achieve this with the help of plugins. They might not go well with the overall aesthetics of the editor, but c’mon – if you heavily need that functionality, why care about the looks, right?
Moving on, the plugin we’re going to use is called RawLineEdit, which views an EOL at the end of each line, in a white looking box (you’ll know what I mean). The only problem with this plugin is that you cannot edit any text inside the editor while in View Mode for line endings. You need to toggle off the option before you can edit again.
First, press the Ctrl + Shift + P (or Command + Shift + P in MacOS) to bring up the command palette in Sublime Text, and search for ‘install:
Select the ‘Package Control: Install Package’ option and press Enter. A new Menu would open where you can search for the RawLineEdit package (or plugin):
Once found, press Enter once again to install the Package. Give it some time. When the installation is complete, a new tab with a Message regarding the plugin will open. But if you now try looking into some file, unfortunately, no Carriage Returns or EOLs will be shown, just yet. What you need to make sure of is to open a file that is already saved and stored on your disk (this can later be changed to work as unsaved files too through the settings for Raw Line Edit). Now, you’d need to actually toggle the option for viewing the hidden characters.
To do this, press Ctrl + Shift + P (or Command + Shift + P in MacOS) to bring up the command palette, and search for ‘Raw Line Edit’:
Here, we’re given two options. The View Line Endings option will show you the EOL in a separate panel. For now, select the Toggle Line Editor Mode option, which will view the EOL directly in the current file.
As you could see, the white boxes with ‘┐’ inside depicts the EOL character. However, as mentioned previously, the only problem is that you cannot edit text while viewing the characters. In order to edit text, you need to toggle the same setting again from the command palette. Once toggled, the EOL characters will be hidden once again.
This sure might be a little inconvenient not being able to see the characters all the time. However, you’d only ever want to view them in case of syntax errors, and for fixing stuff, which would not be a regular occurrence for the most part anyway!
Temporarily highlight Line Endings using find
If you don’t like the use of a plugin for viewing End of Line characters, there’s a quick method you can use to go about it, with the help of Sublime Text’s Find and Replace function. Press Ctrl + f (or Command + f) to enable Find and Replace, and make sure to enable Regular Expressions on the bottom left of the editor window:
Now inside the Search box, type in ‘\n’:
The EOL characters will be highlighted but will not be directly visible, as you could already see in the above image. In comparison to using the plugin, I’d say this trick does not do a bad job either!