
/etc/nginx/sites-available/default
当我编辑没有扩展名的文件(例如或)时,我试图为 nano 设置“默认”语法高亮方案,/etc/ssh/sshd_config
但似乎无法使其工作。
我已将c
语法高亮文件复制到我的文件中/usr/share/nano/default.nanorc
,然后添加include "/usr/share/nano/deafult.nanorc"
到我的~/.nanorc
文件中,但对于没有扩展名的文件,我仍然没有得到高亮显示。
有人知道如何启用此功能吗?
答案1
您可以自行定义。这是来自 Arch Linux 论坛的一个很好的例子。
复制以下代码并保存在/usr/share/nano/作为conf.nanorc
# config file highlighting
syntax "conf" "(\.(conf|config|cfg|cnf|rc|lst|list|defs|ini|desktop|mime|types|preset|cache|seat|service|htaccess)$|(^|/)(\w*crontab|mirrorlist|group|hosts|passwd|rpc|netconfig|shadow|fstab|inittab|inputrc|protocols|sudoers)$|conf.d/|.config/)"
# default text
color magenta "^.*$"
# special values
icolor brightblue "(^|\s|=)(default|true|false|on|off|yes|no)(\s|$)"
# keys
icolor cyan "^\s*(set\s+)?[A-Z0-9_\/\.\%\@+-]+\s*([:]|\>)"
# commands
color blue "^\s*set\s+\<"
# punctuation
color blue "[.]"
# numbers
color red "(^|\s|[[/:|<>(){}=,]|\])[-+]?[0-9](\.?[0-9])*%?($|\>)"
# keys
icolor cyan "^\s*(\$if )?([A-Z0-9_\/\.\%\@+-]|\s)+="
# punctuation
color blue "/"
color brightwhite "(\]|[()<>[{},;:=])"
color brightwhite "(^|\[|\{|\:)\s*-(\s|$)"
# section headings
icolor brightyellow "^\s*(\[([A-Z0-9_\.-]|\s)+\])+\s*$"
color brightcyan "^\s*((Sub)?Section\s*(=|\>)|End(Sub)?Section\s*$)"
color brightcyan "^\s*\$(end)?if(\s|$)"
# URLs
icolor green "\b(([A-Z]+://|www[.])[A-Z0-9/:#?&$=_\.\-]+)(\b|$| )"
# XML-like tags
icolor brightcyan "</?\w+((\s*\w+\s*=)?\s*("[^"]*"|'[^']*'|!?[A-Z0-9_:/]))*(\s*/)?>"
# strings
color yellow "\"(\\.|[^"])*\"" "'(\\.|[^'])*'"
# comments
color white "#.*$"
color blue "^\s*##.*$"
color white "^;.*$"
color white start="<!--" end="-->"
然后将此配置包含在 /etc/nanorc 文件中,如下所示
## Configuration files (catch-all syntax)
include "/usr/share/nano/conf.nanorc"
代码片段中的第一行代码包含一个正则表达式,该表达式定义应使用此语法高亮显示的文件名。每当您遇到与此不匹配的配置文件,但仍想使用语法高亮显示打开它时,您可以使用 nano 的 -Y 开关手动选择此语法,如下所示:
nano -Y conf myConfigFile
答案2
nanorc 文件应该有
syntax "default"
后面没有正则表达式。
答案3
Nano 语法使用和突出显示所有文件没有扩大:
从默认文件创建备份
yes | cp /usr/share/nano/default.nanorc /usr/share/nano/default.nanorc.backup
从配置文件创建副本
yes | cp /usr/share/nano/sh.nanorc /usr/share/nano/default.nanorc
将语法扩展名称更改为默认
sed -i -e 's/syntax "sh" "\\.sh$"/syntax "default"/g' /usr/share/nano/default.nanorc
将所有 .nanrc 文件存储在包含文件中
ls -1 /usr/share/nano/*.nanorc | sed 's/^\//include \//' >> ~/.nanorc