It is lightweight and can be navigated easily, similar to opening a text file in Notepad for instance. One thing it was originally lacking was syntax highlighting which I enjoy a lot. I had to set this up on my laptop so I wanted to talk everyone else through it. The general setup file for nano is a hidden file that should be located in your home directory. If not you can create it and call it .nanorc. The link below is an example of a file you can use and modify to your preference. Rename this to the .nanorc and copy it to your home directory.
From here, you can add the syntax setup to the main file or create separate files for specific coding and scripting languages. I prefer this route so if I want to change what my syntax looks like I only have to go to a file with 8 lines in it.
This example will setup highlighting for python. Line 245 in the link above is where you uncomment the code
include "/usr/share/nano/python.nanorc"
Save this file and cd to /usr/share/nano. If the directory does not exist, create it. Then create a file python.nanorc. This goes for any language you want to create custom syntax highlighting for. Edit this file similar to the code below
## Here is an example for Python.
##
syntax "python" "\.py$"
icolor brightblue "def [0-9A-Z_]+"
color brightcyan "\<(and|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|map|not|or|pass|print|raise|return|try|while)\>"
color brightgreen "['][^']*[^\\][']" "[']{3}.*[^\\][']{3}"
color brightgreen "["][^"]*[^\\]["]" "["]{3}.*[^\\]["]{3}"
color brightgreen start=""""[^"]" end=""""" start="'''[^']" end="'''"
color red "#.*$"
When nano starts, the .nanorc file will look for this python setup file and syntax highlight according to how you want it. These colors will appear for the variables you define in the "". That is what each line has in common. This makes it easier to make those quick changes to code as you are tinkering in the terminal.
No comments:
Post a Comment