服务器上的 Nano 忽略某些语法着色

发布于 2024-10-12 22:48:53 字数 1220 浏览 3 评论 0原文

我通过 ssh 在服务器上使用 nano;在该系统上,nano 默认情况下不启用语法颜色。因此,我复制了这些 nanosyntax 文件(有关替代方案,另请参阅@CraigBarnes 的回答)在服务器上,并将 ~/.nanorc 设置为:

include "~/nanosyntax/syntax-nanorc/php.nanorc"
include "~/nanosyntax/syntax-nanorc/php2.nanorc"
include "~/nanosyntax/syntax-nanorc/sh.nanorc"
include "~/nanosyntax/syntax-nanorc/python.nanorc"
include "~/nanosyntax/syntax-nanorc/html.nanorc"
include "~/nanosyntax/syntax-nanorc/perl.nanorc"
include "~/nanosyntax/syntax-nanorc/ruby.nanorc"
include "~/nanosyntax/syntax-nanorc/js.nanorc"

现在,事情就是这样;如果我只是调用:

nano somefile.php

... 则不会完成 php 语法着色。如果我尝试强制:

nano --syntax=php somefile.php

...仍然没有语法着色(显示为纯文本)。但是,如果我这样做:

nano ~/.nanorc

...那么我得到语法着色(对应于.nanorc类型文件)?!

很明显,语法着色本身是有效的(即 shell 和 nano 都可以) - 但对于某些语言来说,它似乎被忽略了,比如在这种情况下 php ? !

那么,有谁知道发生了什么事 - 我怎样才能获得 php 文件的语法着色?

谢谢,
干杯!

I'm using nano on a server via ssh; on that system, nano doesn't have syntax color enabled by default. So I copied these nanosyntax files (for alternative, see also @CraigBarnes' answer) on the server, and had set up ~/.nanorc as:

include "~/nanosyntax/syntax-nanorc/php.nanorc"
include "~/nanosyntax/syntax-nanorc/php2.nanorc"
include "~/nanosyntax/syntax-nanorc/sh.nanorc"
include "~/nanosyntax/syntax-nanorc/python.nanorc"
include "~/nanosyntax/syntax-nanorc/html.nanorc"
include "~/nanosyntax/syntax-nanorc/perl.nanorc"
include "~/nanosyntax/syntax-nanorc/ruby.nanorc"
include "~/nanosyntax/syntax-nanorc/js.nanorc"

Now, this is the thing; if I just call:

nano somefile.php

... no php syntax coloring is done. If I try to force:

nano --syntax=php somefile.php

... still no syntax coloring (shown as plain text). However, if I do:

nano ~/.nanorc

... then I do get syntax coloring (that corresponds to .nanorc type file) ?!

So obviously, syntax coloring as such works (i.e. shell and nano are capable of it) - except, it seems to be ignored for some languages, like in this case php ?!

So, does anyone know what is going on - and how could I get syntax coloring also for php files?

Thanks,
Cheers!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

酒绊 2024-10-19 22:48:53

我刚刚遇到了同样的问题,我对包含内容进行了一些修改以找到错误。令人惊讶的是,事实证明,更改包含顺序解决了问题:

这有效:

include "~/.nano/nanorc.nanorc"
include "~/.nano/sh.nanorc"
# more includes...

这无法突出显示 sh 文件:

include "~/.nano/sh.nanorc"
include "~/.nano/nanorc.nanorc"
# more includes...

所以我猜这可能是一个错误(在 nano 2.2.2 中;在 nano 2.1.7 中工作正常)

I just ran into the same problem, and I fiddled around a bit with the includes to find the error. Surprisingly, turns out that changing the inclusion order fixed the issue:

This works:

include "~/.nano/nanorc.nanorc"
include "~/.nano/sh.nanorc"
# more includes...

This fails to highlight sh files:

include "~/.nano/sh.nanorc"
include "~/.nano/nanorc.nanorc"
# more includes...

So I guess it's probably a bug (in nano 2.2.2; worked fine in nano 2.1.7)

跨年 2024-10-19 22:48:53

嗯...好吧,看来我使用的服务器已经升级了;最初,nano 默认情况下没有语法着色,这就是我使用自己单独的 ~/.nanorc 的原因。

然而,现在,在升级后的服务器上,nano 似乎默认使用 php 语法着色 - 而我拥有自己的单独的 ~/.nanorc 似乎有冲突;因为,一旦我评论了私有 ~/.nanorc 中的所有条目(使用 #),php 语法着色又回来了!

谁会击杀?! :)
干杯!


编辑:只是添加一些关于 nano 的注释:

如上所述,语法着色是通过 --syntax 开关强制执行的;查看哪些语法可用:

grep 'include' /etc/nanorc |       # find lines containing 'include' in nanorc
  grep -v '^#' |                   # don't process lines that start with '#'
    sed 's_.*/\(.*\)\.nanorc"_\1_' # extract plain filenames

此命令的结果类似于:

nanorc
c
css
debian
gentoo
html
...

因此,要强制“nanorc”语法着色,您可以使用:

nano --syntax=nanorc /usr/share/nano/nanorc.nanorc

.. 或强制“bash”shell 脚本语法着色(对于 bashrc 特别有用) )将是:

nano --syntax=sh ~/.bashrc

Hm... well, it seems there has been an upgrade on that server I was using; originally, nano didn't have syntax coloring by default, which is why I used my own separate ~/.nanorc.

Now, however, on the upgraded server, nano seems to work with php syntax coloring by default - and me having my own separate ~/.nanorc seems to have conflicted; because, once I commented all the entries in the private ~/.nanorc (with an #), php syntax coloring was back!!

Whowouldathunkit ?! :)
Cheers!


EDIT: Just to add a couple of notes about nano:

As noted above, syntax coloring is forced with --syntax switch; to see which syntaxes are available:

grep 'include' /etc/nanorc |       # find lines containing 'include' in nanorc
  grep -v '^#' |                   # don't process lines that start with '#'
    sed 's_.*/\(.*\)\.nanorc"_\1_' # extract plain filenames

Result of this command is something like:

nanorc
c
css
debian
gentoo
html
...

So to force "nanorc" syntax coloring, you use:

nano --syntax=nanorc /usr/share/nano/nanorc.nanorc

.. or forcing "bash" shell script syntax coloring (especially useful with bashrc) would be:

nano --syntax=sh ~/.bashrc
长伴 2024-10-19 22:48:53

Google Code 上的那些“nanosyntax”文件几乎和 Nano 默认附带的文件一样糟糕。

nano 的突出显示引擎比具有嵌套上下文的引擎(例如 GtkSourceView)更基本,但您不必满足于蹩脚的突出显示:

https://github.com/craigbarnes/nanorc

Those "nanosyntax" files on Google Code are nearly as bad as ones that come with nano by default.

nano's highlighting engine is more basic than something with nested contexts (e.g. GtkSourceView) but you don't have to settle for crappy highlighting:

https://github.com/craigbarnes/nanorc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文