If you like programming in the console, it'll be handy to have syntax highlighting in your favorite editor. Vi and Nano are the most used editors, so i'll show how to turn on syntax highlighting for these editors.


Vi

Edit the vimrc file, it's in the home dir:
vi /home/user/.vimrc


Edit the syntax line to what it says below, or add this line to the file if it doesn't exist:
:syntax enable


Syntax highlighting is now turned on for the languages Vi supports highlighting with.


Nano

The process of turning on syntax highlighting on Nano is a bit different, the integration of syntax highlighting in the editor is not that great, certainly not equal to that of an editor like Vi.

Edit the nanorc file, it's in /etc:
nano /etc/nanorc


Go to the syntax section in the file (you can search for "syntax", though in my nanorc file the section is at line 215). You'll see something like the following:
## C/C++

# include "/usr/share/nano/c.nanorc"


## HTML

# include "/usr/share/nano/html.nanorc"


## Perl

# include "/usr/share/nano/perl.nanorc"


## Python

# include "/usr/share/nano/python.nanorc"


## Ruby

# include "/usr/share/nano/ruby.nanorc"


## Java

# include "/usr/share/nano/java.nanorc"


## Assembler

# include "/usr/share/nano/asm.nanorc"


## Bourne shell scripts

# include "/usr/share/nano/sh.nanorc"


You can simply uncomment the file includes for the languages you want syntax highlighting enabled on.

The number of languages Nano offers syntax highlighting for is limited. If you think Vi is too complicated, and Nano doesn't support the language(s) you program in, you can always use Joe, it has by default regex files for syntax highlighting, and for more languages than Nano.



muflix on Sunday 29-04-2012

how to highlight configuration files like
/etc/postfix/main.cf
or
/etc/apache2/apache2.conf

it doesnt work, thx :-)
muflix on Sunday 29-04-2012

with nano (with vim its ok)
muflix on Sunday 29-04-2012

okay i got it, its DIY solution
Jaxprat on Wednesday 20-02-2013

If using "#!/usr/bin/env ruby" for your file header instead of "#!/.../ruby" then you'll want to change the header declaration in the ruby.nanorc to:

header "^#!.*/(env )?ruby[-0-9._]*"

React on this article







Enter the code here: