vim

How to Get Vim Show Hidden Invisible Characters


Vim stands for “Vi improved.” It is a commendable text editor for Unix-like operating systems. vim can be utilized for editing different types of text documents, but it is complemented for editing computer programs. Vim comprises two modes:

Visual Mode:

The visual mode permits the vim user to select the text using the keyboard rather than the mouse. It is considered useful for copying different text lines. Its shortcut is “V.”

Command mode:

Any command in vim command mode starts with the symbol “:”. To switch from visual to command mode, you have to press the escape key once or twice.

Vim features:

Vim is a text editor that is complaint with Vi and works with it. It provides several improvements over Vi, including syntax highlighting, multi-level undo, command-line editing, multiple buffers and windows, filename completion, visual selection, a comprehensive support system, and more. Another fantastic feature of vim is showing invisible characters in a text file. vim use the below-given command for displaying the hidden invisible characters in a text file.

: setlist

Want to hide invisible characters? Switch from list to nolist.

: set nolist

The default symbol characters in vim are given in the table below:

Symbol Character
$ Newline
^| Tab

In this article, we will guide you through the procedure of showing hidden invisible characters of a text file in vim. So let’s get started!

Firstly, we will open a text file in the vim editor. Select any text file for this purpose. In our case, we have chosen the “test_file,” and now we are going to add some text to this file.

$ vim test_file

Insert text into this file by pressing the “Esc” key and switch the editor into command mode.

Type “:wq” for saving this file and then exit the vim editor.

Utilize the list command for checking the presence of the newly created file.

$ ls

Write out the below-given command and view the “test_file” content.

$ cat test_file

Now executing the setlist command will show you the hidden invisible characters of this test file.

: setlist

“^|” represents tab, and “$” points out space in the document.

To show all the characters that are not white spaced, execute this command in the vim editor:

:set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<

This command will show each hidden character except the spaces.

You can also highlight the weird spaces in the file and can customized specified symbols to display.

:set listchars=nbsp:☠,tab:▸␣

Conclusion:

Vim is a text editor used by several Linux users because of its incredible features, including syntax highlighting, multi-level undo, command-line editing, multiple buffers and windows, filename completion, and visual selection, a comprehensive support system. Showing invisible, hidden characters is also one of them. This post shows the method of showing invisible characters and customizing different symbols to show up instead of these characters.

About the author

Talha Saif Malik

Talha is a contributor at Linux Hint with a vision to bring value and do useful things for the world. He loves to read, write and speak about Linux, Data, Computers and Technology.