在 OSX v10.9.5 上编辑 nanorc

editing nanorc on OSX v10.9.5

在我的 VM 上,我在 nano 中为 perl、python 和 bash.

语法突出显示

我通过添加

做到了这一点

include /usr/share/nano/python.nanorc

到我的 ~/.nanorc 文件

但是,我刚买了一台新的 Macbook pro,/usr/share/nano 在那个位置不存在,尽管 vim,emacs 等在那个位置 ...

找到。 -name "nano" returns ./usr/bin/nano,但这只是可执行文件(我认为),而不是我需要的包含 *.nanorc 文件的文件夹。

有人在 10.9.5 上做过吗?

如果您使用的是 Apple 的 nano,则可以将 .nanorc 文件从任何来源复制到主目录中的某个位置,例如 ~/.nano.

nano-highlight repository seems to be an attempt to collect all of the best syntax highlighting .nanorcs in one place. Following the directions there 可能是最简单的解决方案。

如果安装 MacPorts' nano,一些 .nanorc 文件会安装在 /opt/local/share/nano 中(包括一个 python.nanorc)。

大多数 nano-highlight .nanorc 似乎都与 Apple 和 MacPorts nano 兼容,但 Apple nano(较旧)doesn't understand the bash.nanorc 除外。如果您尝试包含其中的 all,那么 nano 都会出现段错误;我不确定该错误是否由特定 .nanorc 触发,但我怀疑它是由于包含太多(无论是哪些)触发的。


UPDATE:.nanorc文件中nano-highlight repository are only partly compatible with Apple nano. Some of the colors will not be used, but no error will be given. According to this comment上的bash.nanorcbug,该问题是BSD差异造成的和 POSIX 正则表达式语法,可以通过使用以下命令修改所有 .nanorc 文件来修复:

sed -i -e 's|\<|[[:<:]]|g;s|\>|[[:>:]]|g' /path/to/nanorc/files/*

MacPorts nano 不受影响(它使用 MacPorts 安装的正则表达式引擎)。