13

I am struggling finding a clear answer on disabling or overriding the color settings for the nano editor.

By default color syntax highlighting is enabled on my system. Clicking ALT+Y disables this, which is exactly what I want my default to be.

Any ideas?

lorem monkey
  • 3,942
  • 3
  • 35
  • 49
seanomlor
  • 973
  • 1
  • 10
  • 23
  • 1
    Do you have lines in your .nanorc that look like `include /usr/share/nano/sh.nanorc`? If so remove them and it should disable syntax highlighting for the language in the file name(sh.nanorc = shell, c.nanorc = c, etc). – Lipongo Nov 03 '12 at 02:06
  • not in my ~/.nanorc file, no. is there a default .nanorc somewhere? – seanomlor Nov 03 '12 at 23:10
  • @seanomlor The global `nanorc` configuration file for nano is located in `/etc` on Linux Mint (Ubuntu). – Attila T Nov 05 '12 at 17:28
  • @AttilaT., ahh, i was looking for a /etc/.nanorc file. it's simply /etc/nanorc. thank you. – seanomlor Nov 08 '12 at 23:01
  • There's no command line argument to run nano only once with color disabled? I mean, a solution without saving configurations into files. – blagus Sep 02 '16 at 02:32
  • 1
    surely **-Ynone** is the simple answer here ! – Fattie Dec 13 '18 at 14:08

7 Answers7

17

To disable syntax highlighting write following lines into ~/.nanorc:

set quiet
syntax "disabled" "."

The first line prevent error reporting. The second line defines a new color syntax.

You can also define a single syntax containing your favorite color in your ~/.nanorc:

syntax "disabled" "."
color brightgreen,black "."

I hope this helps.

Jürgen G.
  • 186
  • 2
  • 3
15

For future references, I would add that you can run nano without colors using the command line parameter -Y

nano -Ynone myfile.txt

The "none" syntax is reserved; specifying it on the command line is the same as not having a syntax at all.

You can set an alias in your .bash_profile file:

alias nano='nano -Ynone'
Adam
  • 17,838
  • 32
  • 54
3

This worked for me better than above since I run a white background terminal. It just makes all the text black again.

set quiet
syntax "disabled" "."
color black "."
utdrmac
  • 731
  • 5
  • 17
3

Add the following to your ~/.nanorc file to disable syntax highlighting for all file types.

syntax "" ""
color white ""
Harry
  • 31
  • 3
  • This answer was perfect! Did exactly what I wanted which was to completely disable all color stuff. The accepted answer above did NOT work for me but this did. (nano 2.2.6) – utdrmac Apr 13 '16 at 14:35
  • This no longer works because the empty string is no longer a valid syntax name. – Peter Eisentraut Apr 28 '18 at 23:19
1

There's a limitation in nano that every syntax requires at least one color rule. And, on nano 4.0 at least, the color rule's regex can't be empty. But you can make a rule that just targets whitespace, or a rule that just targets an empty line.

I'd recommend defining an extremely minimal color scheme first that applies colors in a way that you can tolerate. For example, this rule sets the background to green in places where you have trailing whitespace.

syntax "nothing" "."
color ,green "[[:space:]]+$"

You can also create a rule that targets an empty line. This rule will have no visible effect, but the right hand side is technically not empty so nano will accept it.

syntax "nothing" "."
color green "^$"
Greg Nisbet
  • 6,710
  • 3
  • 25
  • 65
0

Instead of using syntax "disabled" "." and forcibly keeping all hghlighting off, add this to bottom of your ~/.nanorc and use an alias when you want no highlighting:

 ## Syntax - Black and White only (for override)
 syntax "blackandwhite" "."
 color white,black "."

then:

 nano --syntax=blackandwhite myfile-nohighlighting.php

(Too much to type? Then use an alias in your .bashrc/shellrc):

 alias bw='nano --syntax=blackandwhite'

or you could simply (See @Adam answer):

 alias bw='nano -Ynone'

And avoid creating a highlight profile.

then you can open using the alias and have no highlighting:

 bw myfile.php

Using it this way, you also leave highlighting available in the .rc for when you may need it..

B. Shea
  • 829
  • 14
  • 29
0

This answer is for nano version 5.9 on Termux version 0.117. Disclaimer: I don't understand exactly how .nanorc code works here (so, it possibly should be a bit different, but it seems to work).

To turn syntax highlighting off for all file types, do this in ~/.nanorc:

syntax "all" "\.*$"
color white,black "^.*$"

In the latter set of double quotes for each line, those are regular expressions. On the first line, the regex matches any file extension (I don't think "all" actually does anything; I just had to type a word in there; it doesn't work if it's blank or has multiple words). On the second line, the regex matches the entire text of the document, and sets the foreground (the font color) to white, and the highlight background to black.

I guess this does the same thing in a simpler way (I suppose it evaluates each character at a time):

syntax "all" "."
color white,black "."

If you just want to do the same thing for one kind of file, here is an example for .txt files:

syntax "txt" "\.txt$"
color white,black "^.*$"

Or

syntax "txt" "\.txt$"
color white,black "."

If you don't want to specify the background highlight color (which is not the entire background color of nano, btw), too, then instead of doing color white,black . . . do color white . . ..

Note: My personal reason for wanting to disable syntax highlighting was because comments beginning with # were a different color in plain text files and similar (and I didn't want that). These solutions make the comments white.

Brōtsyorfuzthrāx
  • 4,387
  • 4
  • 34
  • 56