How to enable syntax highlighting for Markdown files in GNU Nano

GNU nano is a simple terminal-based text editor. Though not as powerful as Emacs or Vim, it is easy to learn and use. A lot of developers prefer this editor as it's very simple to use and pretty useful when you only want to edit a single file quickly on your server.

One of those files that you need to change often in this kind of editor are configuration file, like markdown files. Nano offers syntax highlighting for many file types, however not for Markdown files. If you want to highlight this kind of files as well, you will need to follow an extra step. In this article, we'll show you how to highlight Markdown files on nano in Ubuntu.

1. List available Nano Syntax Highlight Files

As first step, discover which languages are available in nano to highlight its syntax with the following command:

ls /usr/share/nano/

This will list all the nano syntax highlighting files in the given directory:

If you don't find the markdown.nanorc file, then you can install it with the next step.

2. Create Markdown Nano Syntax Highlighting File

In order to provide syntax highlighting to your file, if the default file doesn't exist, you need to create the syntax highlighting file for this language. This file is the markdown.nanorc file and you need to create it in the mentioned directory. Run nano to create the file:

Visit the official repository of Nano Highlight, a spiffy collection of nano syntax highlighting files for more information and languages available for nano. This file will be automatically added into nano and will highlight markdown files. Save changes and proceed with the last step.

3. Create Test Markdown File to see results

As final step, you need to test wheter the highlight works or not. Proceed to create a test file with nano and write some Markdown based content on it, for example: