1. Overview

Gedit is the official text editor for the GNOME Linux desktop environment. It features a simple and intuitive interface and supports a wide variety of programming languages.

When working with text files in Gedit, it can be helpful to display non-printing characters such as newlines, tabs, carriage returns, and others. In fact, these characters represent various commands and functions that control the display or formatting of text.

In this tutorial, we’ll go through how to enable the display of control characters in Gedit.

Throughout the article, we’ll use Gedit version 41.0 on Ubuntu 22.04 with GNOME 42.5.

2. What Are Control Characters?

Before we learn how to display control characters in Gedit, let’s take a moment to understand what they are. Control characters are special characters that don’t represent printable text, but control the display or formatting of text. Furthermore, they translate to non-printing actions like tabbing to a new column or moving the pointer to a new line.

The Open Group Base Specifications Issue, 7 2018 Edition provides an inclusive list of control characters and more detailed information.

In addition, certain contexts use a special notation to represent control characters, which usually consists of a backslash \, followed by a letter that indicates the specific control character.

Now, let’s take a closer look at some of the most common ones.

2.1. Line Feed (LF)

Also known as newline, it moves the cursor to the next line. Its ASCII code is 10 or hexadecimal 0x0A, and its escape sequence is \n.

2.2. Carriage Return (CR)

The CR control character moves the cursor to the beginning of the current line. Its ASCII code is 13 or hexadecimal 0x0D, and its escape sequence is \r.

Unix and Windows systems use this character in different ways when dealing with line endings. The LF character alone represents the line ending on most Unix systems, while Windows uses the CRLF character combination \r\n.

2.3. Tab (TAB)

This character moves the cursor to the next tab stop. Its ASCII code is 9 or hexadecimal 0x09, and its escape sequence is \t.

Commonly, these and other characters are also known as whitespace.

3. Enabling Control Character Display in Gedit

Now that we have a good understanding of control characters and their uses, let’s take a look at how to enable their display in Gedit.

By default, Gedit doesn’t display control characters, but enabling them is a straightforward operation. Older versions of Gedit may have a slightly different process, but the general idea is the same.

First, let’s install the gedit-plugins package using apt:

$ sudo apt-get update && sudo apt-get install gedit-plugins

Once the installation is complete, we can enable the control character display:

  1. Open Gedit
  2. Click on the hamburger menu in the top-right corner of the window:
    Gedit hamburger menu
  3. Click on Preferences:
    gedit preferences selection
  4. Click on Plugins:
    Gedit plugin selection
  5. Enable the Draw Spaces plugin by checking the corresponding checkbox:
    Gedit Draw Spaces plugin's checkbox
  6. Click on the Draw Spaces plugin’s title or description to select it:
    Gedit Draw Spaces plugin selection
  7. Click on the Preferences button:
    Gedit plugin preferences button
  8. Select the special characters to display by checking the corresponding checkboxes:
    Gedit Draw Spaces plugin preferences
  9. Click on Close:
    Gedit Draw Spaces plugin preferences
  10. Click on the X in the top-right corner of the Preferences dialogue box to close it and get back to the editor:
    Gedit preferences dialogue box
  11. Gedit should now display all control characters such as newlines and tabs using their respective symbols:
    Gedit example text

After getting through the process of enabling the display of control characters, let’s see how to disable them.

4. Disabling Control Character Display in Gedit

In essence, to disable control character display, we can go through the above steps, up to step 4. Then, we can uncheck the Draw Spaces plugin’s checkbox to disable it.

On the other hand, if we need to disable specific control characters, we can do so by simply unchecking the relevant checkboxes in the Draw Spaces plugin options.

Moreover, in step 8, we are free to select the control characters we want and don’t want to display by checking and unchecking the corresponding checkboxes:Gedit example text
In the example above, we have disabled the LF characters. Consequently, the resulting example text is not showing them:
Gedit example text
Finally, we can now toggle just the control characters that we need, and Gedit will reflect the changes immediately.

5. Conclusion

In summary, control characters are non-printing elements for text formatting, as we learned in this article. Additionally, we saw that enabling control character display in Gedit is a simple process that can make working with text files much easier.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.