Skip to main content

Configure nano for Command Line Development

Tags

GNU Nano

On my main computer at home I recently made the switch Linux.  I skipped the dual boot with Windows and dove right in head first with a very simple install of Fedora 20.  I am really liking it so far, my only complaints are Gnome 3, which if you are a Gnome user, you know what I mean, and getting up and running in a development environment.  Now by default, if I am developing anything on the web in a Windows or Mac environment I am using Sublime Text 3 for the code and Xampp for the localhost.  Well, I installed Xampp/Lampp on Fedora very easily, but I was really torn about installing Sublime Text right away.  I thought, “should try something new for a couple of months and develop all code straight out of the terminal like they used to do before we had all of the IDE's to help us out?”  That sounded like an awesome challenge to me, so I thought I would give it at least two months and see how I liked it.   

My first hurdle was to find a great terminal editor that I could rely on to write code in.  My first thought was nano, since I use it a lot at work when I am wearing my system admin hat, but I did not want to be too quick to decide.  I looked around and tried Vi, Vim, and Emacs, but was not happy with any of those choices, so I ended up right back where I started, with the nano editor.  My second hurdle was configuring nano to except syntax highlighting and some of the great features I have come to love in text editors.  Below are some of those configuration settings enabled and created.

Prerequisites

  1.  A Linux OS, with terminal access and the ability to run sudo commands
  2.  nano 2.2 or greater installed.

 

To configure global settings for the nano text editor for all uses on your machine, navigate out to the directory /etc and open the file nanorc.  Optionally, configure nano on a user by user basis by creating a .nanorc file in their home directory.

#open up the global configuration file for nano, with nano ;-)
$ sudo nano /etc/nanorc

To enable mouse support, where you can click on an item anywhere it view and the cursor will go there, enable the setting:

## Enable mouse support, if available for your system.  When enabled,
## mouse clicks can be used to place the cursor, set the mark (with a
## double click), and execute shortcuts.  The mouse will work in the X
## Window System, and on the console when gpm is running.
##
set mouse

To enable text to not wrap down to the next line, enable the following:

## Don't wrap text at all.
set nowrap

To enable smooth scroll from page to page, instead of choppy scrolling, enable the following:

## Use smooth scrolling as the default.
set smooth

To configure a color for comments in any file that is opened with nano, add this to the file:

syntax "comments" ".*"
color blue "^#.*"

To enable text highlighting for most all of your C derivatives, make sure the following include statements are not commented out:

## Nanorc files
include "/usr/share/nano/nanorc.nanorc"
 
## C/C++
include "/usr/share/nano/c.nanorc"
 
## Makefiles
include "/usr/share/nano/makefile.nanorc"
 
## Cascading Style Sheets
include "/usr/share/nano/css.nanorc"
 
## Debian files
include "/usr/share/nano/debian.nanorc"
 
## Gentoo files
include "/usr/share/nano/gentoo.nanorc"
 
## HTML
include "/usr/share/nano/html.nanorc"
 
## PHP
include "/usr/share/nano/php.nanorc"
 
## TCL
include "/usr/share/nano/tcl.nanorc"
 
## TeX
include "/usr/share/nano/tex.nanorc"
 
## Quoted emails (under e.g. mutt)
# include "/usr/share/nano/mutt.nanorc"
 
## Patch files
include "/usr/share/nano/patch.nanorc"
 
## Manpages
include "/usr/share/nano/man.nanorc"
 
## Groff
include "/usr/share/nano/groff.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"
 
## Fortran
include "/usr/share/nano/fortran.nanorc"
 
## Objective-C
include "/usr/share/nano/objc.nanorc"
 
## OCaml
include "/usr/share/nano/ocaml.nanorc"
 
## AWK
include "/usr/share/nano/awk.nanorc"
 
## Assembler
include "/usr/share/nano/asm.nanorc"
 
## Bourne shell scripts
include "/usr/share/nano/sh.nanorc"
 
## POV-Ray
include "/usr/share/nano/pov.nanorc"
 
## XML-type files
include "/usr/share/nano/xml.nanorc"

If you want to add to add a file extension to one of the syntax nanorc files.  Navigate out there and add the extension.  For example, since I do a lot of Drupal development, I needed to have the php.nanorc file recognize the .install and .module extensions.  Here's how I did it:

#I added the "\.install?$" "\.module?$" addition to the upfront declaration of the PHP extension
 
## Here is an example for PHP
##
syntax "php" "\.php[2345s~]?$" "\.install?$" "\.module?$"

Member for

3 years 9 months
Matt Eaton

Long time mobile team lead with a love for network engineering, security, IoT, oss, writing, wireless, and mobile.  Avid runner and determined health nut living in the greater Chicagoland area.

Comments

Shahid Siddique

Thu, 09/24/2020 - 03:01 AM

I have used Sublime text, Atom and bracket and I liked Sublime text better than all. Recently due to license conflict with my org, I have to move to Atom.