简体   繁体   English

如何注释掉 Linux 配置文件中的多行?

[英]How to comment out multiple lines in a Linux config file?

Given:鉴于:

code

in /etc/nginx/sites-available/mySite.conf ./etc/nginx/sites-available/mySite.conf We know that我们知道

#Code

means it will get ignored.意味着它将被忽略。 But how if I want to comment out:但是如果我想注释掉怎么办:

Code
Code
Code
Code

without using # ?不使用# ? I have people see use ''' in python to comment out multiple lines.我有人看到在 python 中使用'''来注释多行。 Does this work for Linux config files as well?这也适用于 Linux 配置文件吗?

There's no standard "Linux config file" -- the syntax is totally dependent on what program is reading the file and how that program is parsing it.没有标准的“Linux 配置文件”——语法完全取决于读取文件的程序以及该程序如何解析它。

Nginx recognizes only lines beginning with # as comments. Nginx 仅将以#开头的行识别为注释。http://nginx.org/en/docs/beginners_guide.html#conf_structurehttp://nginx.org/en/docs/beginners_guide.html#conf_structure

I think we can try out the vim editor bulk comment method as follows我觉得我们可以试试vim编辑器批量评论的方法如下

Put your cursor on the first # character, press CtrlV (or CtrlQ for gVim), and go down until the last commented line and press x, that will delete all the # characters vertically.将光标放在第一个 # 字符上,按 CtrlV(或 CtrlQ 用于 gVim),然后向下直到最后一个注释行并按 x,这将垂直删除所有 # 字符。

For commenting a block of text is almost the same:注释一段文本几乎是一样的:

First, go to the first line you want to comment, press CtrlV.首先,转到要评论的第一行,按 CtrlV。 This will put the editor in the VISUAL BLOCK mode.这会将编辑器置于 VISUAL BLOCK 模式。 Then using the arrow key and select until the last line Now press ShiftI, which will put the editor in INSERT mode and then press #.然后使用箭头键并选择直到最后一行 现在按 ShiftI,这会将编辑器置于 INSERT 模式,然后按 #。 This will add a hash to the first line.这将在第一行添加一个哈希值。 Then press Esc (give it a second), and it will insert a # character on all other selected lines.然后按 Esc(稍等),它将在所有其他选定行上插入 # 字符。 For the stripped-down version of vim shipped with debian/ubuntu by default, type : s/^/# in the third step instead (any remaining highlighting of the first character of each line can be removed with :nohl).对于 debian/ubuntu 默认随附的精简版 vim,请在第三步中键入 :s/^/#(可以使用 :nohl 删除每行第一个字符的任何剩余突出显示)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM