What is Vim?
Vim is a very useful command line interface text editing tool which is widely used for editing program code as well as text files.
This tool was created as an improvement on the Vi text editing utility and comes default with nearly all Linux distributions.
Sometimes files containing code will contain hidden characters but with Vim we’re able to display hidden characters or special characters easily.
In this article we’ll go over some Vim basics and how to display hidden characters and special characters within files.
Getting Started With Vim
There are some basic keys everyone who works in the command line interface (CLI) should know to get started with Vim. Below we will cover those items:
How to open or create files
$ vim example-file.txt
How to save changes
To save a file while using vim you would use :w
How to exit files
To exit a file you would use :q (remember q for quit)
How to save and exit files:
You can combine w and q together by using :wq
How to enter into insert mode for file editing:
When you first open a document up with Vim, by default the editor is in “normal” mode.
In order to edit you will need to hit ‘a’ which puts you into insert mode.
On the other hand, before being able to save or exit, you need to exit insert mode which can be done by hitting the ESC key.
Show Hidden Characters
Hidden characters are basically additional spaces or “blank spaces” and sometimes they can create syntax issues if working with certain programming languages.
Coding languages such as Python or YAML are stricter on their indentation rules for syntax and with Vim you’re able to determine if the proper line breaks or spaces are in place.
Using :set list to show hidden characters
To show hidden characters or blank spaces on any line you can use the following command within Vim for those locations to be displayed:
:set list
As shown in the image above, when we are using the ‘:set list’ command we can see how Vim displayed each end of line (eol) location or blank spaces with a $ symbol to highlight those locations.
Using ‘set listchars’ to change the symbols used for hidden characters
There are a few different items which are considered to be blank spaces or hidden characters which are represented by default with the $ symbol.
If you wanted to use something other than the default $ symbol for every end of line (eol), you could change it to be the * symbol such as in the below example.
This can be done by entering in the following command:
:set listchars=eol:*
As shown below, this makes it so every “end of line” (eol) will be displayed with the * character rather than a $ character.
It is also very helpful to have a different symbol or character for trailing whitespace. Luckily we can adjust this with the ‘trail’ option in the same manner as above.
Shown below will set end of line (eol) to use the * symbol and trailing spaces (trail) to use the ^ symbol so they can be differentiated a bit further.
:set listchars=eol:*,trail:^
Using :set nolist to hide hidden characters
On the other hand, if you wanted to revert these changes and hide hidden characters we can use the following:
:set nolist
Conclusion
Overall it is important to know the basics of Vim and how to show hidden characters. If you are creating code with YAML or Python (as example) this could save you many headaches by helping find areas where syntax is causing an issue within a file.
Leave a Reply