简体   繁体   中英

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

Given:

code

in /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. Does this work for Linux config files as well?

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.

Nginx recognizes only lines beginning with # as comments. http://nginx.org/en/docs/beginners_guide.html#conf_structure

I think we can try out the vim editor bulk comment method as follows

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.

For commenting a block of text is almost the same:

First, go to the first line you want to comment, press CtrlV. This will put the editor in the VISUAL BLOCK mode. 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 #. 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. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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