質問

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?

役に立ちましたか?

解決

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.

他のヒント

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'

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 "."

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

syntax "" ""
color white ""

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..

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 "^$"
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top