在Mac OS X 10.7 (Lion)中突出显示Nano语法?

时间:2022-06-19 22:44:37

How to enable syntax highlighting for nano in Mac OS X 10.7 (Lion)?

如何在Mac OS X 10.7 (Lion)中启用nano的语法高亮显示?

According to what I found so far on Google is that it has got to do with /.nanorc file. I have no idea how to get it or make it?

根据我在谷歌上的发现,它与/有关。nanorc文件。我不知道如何得到它或做成它?

When I try to find nano in my terminal this is what I get:

当我试图在我的终端上找到nano时,我得到的是:

Notra:~ Sukhvir$ whereis nano
/usr/bin/nano

According to what I found on Internet this is the file I need to edit:

根据我在网上找到的资料,这是我需要编辑的文件:

~/.nanorc

But how do I get to it/how to open it/if I don't have it then how to make it?

但是我怎样才能达到它/如何打开它/如果我没有它那么怎么做呢?

I am a bit new to programming folks, so step-by-step instructions will be highly appreciated.

我对编程人员有点陌生,所以一步一步的指导将被高度赞赏。

I need it for C mainly.

我主要用在C上。

According to what I found online, I have to paste this into the .nanorc file:

根据我在网上找到的,我必须把它粘贴到。nanorc文件中:

include "/usr/share/nano/nanorc.nanorc"
include "/usr/share/nano/c.nanorc"

However this will not work because there is no such directory as /usr/share/nano.

然而,这将不起作用,因为不存在/usr/ share/nano这样的目录。

I also just did ls /usr/share/ and according to the results there is no nano in that directory. Is this a Mac OS X 10.7 (Lion) issue or an issue on my Mac?

我还做了ls /usr/share/,根据结果,在那个目录中没有nano。这是Mac OS X 10.7 (Lion)问题还是Mac上的问题?

6 个解决方案

#1


22  

Here are some steps to help you out.

这里有一些方法可以帮助你。

  1. Create a new directory in /usr/local/share/ called 'nano' like this:
  2. 在/usr/local/share/中创建一个名为“nano”的新目录,如下所示:

mkdir /usr/local/share/nano

mkdir /usr/local/share/nano

  1. Now, using nano, make a nano resource file for your C syntax like this:
  2. 现在,使用nano,为C语法创建一个nano资源文件,如下所示:

nano /usr/local/share/nano/c.nanorc`

纳米/usr/local/share/nano/c.nanorc”

  1. Now put your C code highlighting in this file and save it. Here is a link to some possible C syntax highlighting:
  2. 现在将C代码高亮显示在这个文件中并保存它。下面是一些可能的C语法高亮显示的链接:

http://code.google.com/p/nanosyntax/source/browse/trunk/syntax-nanorc/c.nanorc

http://code.google.com/p/nanosyntax/source/browse/trunk/syntax-nanorc/c.nanorc

  1. Save that file and now open your user’s nano resource file by typing:
  2. 保存该文件,然后输入以下命令打开用户的nano资源文件:

nano ~/.nanorc

纳米~ / .nanorc

  1. In this file, add a reference to the c.nanorc file you just made like this:
  2. 在这个文件中,向c添加一个引用。nanorc文件你就是这样做的:

include "/usr/local/share/nano/c.nanorc"

包括“/ usr /地方/分享/纳米/ c.nanorc”

  1. Save your user resource file.
  2. 保存用户资源文件。

Now, when you open up C files, you should see syntax highlighting. You can add additional syntax highlighting for different types of files using the same method. Just add more lines to your ~/.nanorc file.

现在,当您打开C文件时,您应该会看到语法高亮显示。您可以使用相同的方法为不同类型的文件添加额外的语法高亮显示。只要在你的~/添加更多的行。nanorc文件。

Note that depending on your user permissions, you may have to precede some of the above commands with sudo and then enter your root password.

注意,根据您的用户权限,您可能需要在上面的一些命令前面加上sudo,然后输入根密码。

#2


45  

On Mac, Homebrew (brew) will allow you to easily upgrade nano to a newer version than the one that came with Mac OSX.

在Mac上,Homebrew (brew)可以让你轻松地将nano升级到比Mac OSX更新的版本。

Install brew, then install a new version of nano from the Terminal.

安装brew,然后从终端安装新款nano。

brew install nano

Installing this way includes the /usr/local/share/nano folder containing the default syntax highlight files. You can now include "/usr/local/share/nano/c.nanorc" in ~/.nanorc.

安装这种方式包括/usr/local/share/nano文件夹,其中包含默认语法突出显示文件。您现在可以包括“/usr/local/share/nano/c”。在~ / .nanorc nanorc”。

Bonus: a run-once one-liner to add all languages.

附加功能:添加所有语言的一次性一行程序。

/bin/ls /usr/local/share/nano/*.nanorc | xargs -I {} echo 'include "{}"' >> ~/.nanorc

#3


11  

I'm maintaining a bunch of fairly accurate syntax definitions for nano here: https://github.com/craigbarnes/nanorc. The default "example" definitions that come with nano are very poor quality, as are those mentioned above.

我在这里为nano保留了一些相当准确的语法定义:https://github.com/craigbarnes/nanorc。和上面提到的一样,nano的默认“示例”定义质量很差。

#4


1  

2018 Update

2018年更新

  1. Install Homebrew so you can download latest version of nano
  2. 安装Homebrew,你可以下载最新版本的nano
  3. brew install nano
  4. 酿造安装纳米
  5. nano ~/.nanorc
  6. 纳米~ / .nanorc
  7. Add file path to homebrew nano's syntax highlighting
    • (updated with new langs such as JS)
    • (用JS等新语言更新)
    • include "/usr/local/Cellar/nano/*/share/nano/*.nanorc"
    • 包括“/ usr /地方/地窖/纳米/ * /分享/纳米/ * .nanorc”
  8. 在homebrew nano的语法高亮显示中添加文件路径(使用新的语言如JS更新)包括“/usr/local/Cellar/nano/*/share/nano/*.nanorc”

1st * allows us to include whichever version of nano you have, instead of 2.9.3 (for example). Second * includes all .nanorc files so we have syntax highlighting for all languages that are included!

1 *允许我们包含任何版本的nano,而不是2.9.3(例如)。第二*包含所有.nanorc文件,因此我们对所有包含的语言都有语法高亮显示!


Testing

测试

cd ~/Desktop
touch test.py
touch test.js
nano test.py
nano test.js

Further .nanorc Customization

进一步.nanorc定制

I added "set mouse" and "set smooth" to my .nanorc file as well. This allows for mouse use and smooth scrolling. Find more info on these options by running nano --help.

我还在.nanorc文件中添加了“set mouse”和“set smooth”。这允许鼠标使用和平滑滚动。通过运行nano找到更多关于这些选项的信息——帮助。


Updated Syntax Highlighting

更新的语法高亮显示

https://github.com/scopatz/nanorc has "improved" syntax highlighting, if desired.

如果需要,https://github.com/scopatz/nanorc已经“改进”语法高亮显示。

#5


0  

As mentioned by Mark Mikofski in the comment to another answer, this is the maintained repo for nanorc files:

Mark Mikofski在另一个答案的评论中提到,这是维护的nanorc文件的repo:

https://github.com/scopatz/nanorc

https://github.com/scopatz/nanorc

#6


0  

Easy flow:

brew update && brew install nano

brew更新& brew安装nano

After new nano is installed add this line to ~/.nanorc to enable syntax highlighting for all provided syntaxes:

新nano安装后,将这一行添加到~/中。nanorc允许语法高亮显示所有提供的语法:

include /usr/local/share/nano/*.nanorc

包括/usr/local/share/nano/*.nanorc

#1


22  

Here are some steps to help you out.

这里有一些方法可以帮助你。

  1. Create a new directory in /usr/local/share/ called 'nano' like this:
  2. 在/usr/local/share/中创建一个名为“nano”的新目录,如下所示:

mkdir /usr/local/share/nano

mkdir /usr/local/share/nano

  1. Now, using nano, make a nano resource file for your C syntax like this:
  2. 现在,使用nano,为C语法创建一个nano资源文件,如下所示:

nano /usr/local/share/nano/c.nanorc`

纳米/usr/local/share/nano/c.nanorc”

  1. Now put your C code highlighting in this file and save it. Here is a link to some possible C syntax highlighting:
  2. 现在将C代码高亮显示在这个文件中并保存它。下面是一些可能的C语法高亮显示的链接:

http://code.google.com/p/nanosyntax/source/browse/trunk/syntax-nanorc/c.nanorc

http://code.google.com/p/nanosyntax/source/browse/trunk/syntax-nanorc/c.nanorc

  1. Save that file and now open your user’s nano resource file by typing:
  2. 保存该文件,然后输入以下命令打开用户的nano资源文件:

nano ~/.nanorc

纳米~ / .nanorc

  1. In this file, add a reference to the c.nanorc file you just made like this:
  2. 在这个文件中,向c添加一个引用。nanorc文件你就是这样做的:

include "/usr/local/share/nano/c.nanorc"

包括“/ usr /地方/分享/纳米/ c.nanorc”

  1. Save your user resource file.
  2. 保存用户资源文件。

Now, when you open up C files, you should see syntax highlighting. You can add additional syntax highlighting for different types of files using the same method. Just add more lines to your ~/.nanorc file.

现在,当您打开C文件时,您应该会看到语法高亮显示。您可以使用相同的方法为不同类型的文件添加额外的语法高亮显示。只要在你的~/添加更多的行。nanorc文件。

Note that depending on your user permissions, you may have to precede some of the above commands with sudo and then enter your root password.

注意,根据您的用户权限,您可能需要在上面的一些命令前面加上sudo,然后输入根密码。

#2


45  

On Mac, Homebrew (brew) will allow you to easily upgrade nano to a newer version than the one that came with Mac OSX.

在Mac上,Homebrew (brew)可以让你轻松地将nano升级到比Mac OSX更新的版本。

Install brew, then install a new version of nano from the Terminal.

安装brew,然后从终端安装新款nano。

brew install nano

Installing this way includes the /usr/local/share/nano folder containing the default syntax highlight files. You can now include "/usr/local/share/nano/c.nanorc" in ~/.nanorc.

安装这种方式包括/usr/local/share/nano文件夹,其中包含默认语法突出显示文件。您现在可以包括“/usr/local/share/nano/c”。在~ / .nanorc nanorc”。

Bonus: a run-once one-liner to add all languages.

附加功能:添加所有语言的一次性一行程序。

/bin/ls /usr/local/share/nano/*.nanorc | xargs -I {} echo 'include "{}"' >> ~/.nanorc

#3


11  

I'm maintaining a bunch of fairly accurate syntax definitions for nano here: https://github.com/craigbarnes/nanorc. The default "example" definitions that come with nano are very poor quality, as are those mentioned above.

我在这里为nano保留了一些相当准确的语法定义:https://github.com/craigbarnes/nanorc。和上面提到的一样,nano的默认“示例”定义质量很差。

#4


1  

2018 Update

2018年更新

  1. Install Homebrew so you can download latest version of nano
  2. 安装Homebrew,你可以下载最新版本的nano
  3. brew install nano
  4. 酿造安装纳米
  5. nano ~/.nanorc
  6. 纳米~ / .nanorc
  7. Add file path to homebrew nano's syntax highlighting
    • (updated with new langs such as JS)
    • (用JS等新语言更新)
    • include "/usr/local/Cellar/nano/*/share/nano/*.nanorc"
    • 包括“/ usr /地方/地窖/纳米/ * /分享/纳米/ * .nanorc”
  8. 在homebrew nano的语法高亮显示中添加文件路径(使用新的语言如JS更新)包括“/usr/local/Cellar/nano/*/share/nano/*.nanorc”

1st * allows us to include whichever version of nano you have, instead of 2.9.3 (for example). Second * includes all .nanorc files so we have syntax highlighting for all languages that are included!

1 *允许我们包含任何版本的nano,而不是2.9.3(例如)。第二*包含所有.nanorc文件,因此我们对所有包含的语言都有语法高亮显示!


Testing

测试

cd ~/Desktop
touch test.py
touch test.js
nano test.py
nano test.js

Further .nanorc Customization

进一步.nanorc定制

I added "set mouse" and "set smooth" to my .nanorc file as well. This allows for mouse use and smooth scrolling. Find more info on these options by running nano --help.

我还在.nanorc文件中添加了“set mouse”和“set smooth”。这允许鼠标使用和平滑滚动。通过运行nano找到更多关于这些选项的信息——帮助。


Updated Syntax Highlighting

更新的语法高亮显示

https://github.com/scopatz/nanorc has "improved" syntax highlighting, if desired.

如果需要,https://github.com/scopatz/nanorc已经“改进”语法高亮显示。

#5


0  

As mentioned by Mark Mikofski in the comment to another answer, this is the maintained repo for nanorc files:

Mark Mikofski在另一个答案的评论中提到,这是维护的nanorc文件的repo:

https://github.com/scopatz/nanorc

https://github.com/scopatz/nanorc

#6


0  

Easy flow:

brew update && brew install nano

brew更新& brew安装nano

After new nano is installed add this line to ~/.nanorc to enable syntax highlighting for all provided syntaxes:

新nano安装后,将这一行添加到~/中。nanorc允许语法高亮显示所有提供的语法:

include /usr/local/share/nano/*.nanorc

包括/usr/local/share/nano/*.nanorc