服务器上的 Nano 忽略某些语法着色
我通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚遇到了同样的问题,我对包含内容进行了一些修改以找到错误。令人惊讶的是,事实证明,更改包含顺序解决了问题:
这有效:
这无法突出显示 sh 文件:
所以我猜这可能是一个错误(在 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:
This fails to highlight sh files:
So I guess it's probably a bug (in nano 2.2.2; worked fine in nano 2.1.7)
嗯...好吧,看来我使用的服务器已经升级了;最初,
nano
默认情况下没有语法着色,这就是我使用自己单独的~/.nanorc
的原因。然而,现在,在升级后的服务器上,
nano
似乎默认使用 php 语法着色 - 而我拥有自己的单独的~/.nanorc
似乎有冲突;因为,一旦我评论了私有~/.nanorc
中的所有条目(使用#
),php 语法着色又回来了!谁会击杀?! :)
干杯!
编辑:只是添加一些关于 nano 的注释:
如上所述,语法着色是通过
--syntax
开关强制执行的;查看哪些语法可用:此命令的结果类似于:
因此,要强制“nanorc”语法着色,您可以使用:
.. 或强制“bash”shell 脚本语法着色(对于 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:Result of this command is something like:
So to force "nanorc" syntax coloring, you use:
.. or forcing "bash" shell script syntax coloring (especially useful with
bashrc
) would be: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