SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am editing xorg.conf and have a few sections that I would like to comment, but typing i then x then <escape> then j then h then i, etc is annoying. Especially when I want to comment sections that are 50 lines in a row but I don't want to delete them as I may want to use them in the future. How would I stick a comment at the beginning of 'x' number of lines in vim?
I am editing xorg.conf and have a few sections that I would like to comment, but typing i then x then <escape> then j then h then i, etc is annoying. Especially when I want to comment sections that are 50 lines in a row but I don't want to delete them as I may want to use them in the future. How would I stick a comment at the beginning of 'x' number of lines in vim?
The colon is command mode, obviously
x and y is a range of line numbers you want to affect
s is a sed substitution, the caret (^) means the beginning of the line
The sharp (#) is the comment character, again obviously
I put a space after the comment, but it isn't necessary, substitute any string that suits you.
If you want to get more fancy, you could use external text filters such as boxes or indent. Usually this is for things like C source files instead of xorg.conf files.
For example, if you type out this code:
Code:
This is the program header that explains some stuff about the program
itself and may have a long copyright clause in addition. Blah, blah,
blah. Blah, blah, blah, blah.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
This software is dedicated to my dear, sweet mother.
#include <stdio.h>
int main() { printf("Real code begins on line 20.\n"); return 0;}
And this type into ex:
Code:
:1,18!boxes
The result looks all pretty like so:
Code:
/*************************************************************************/
/* This is the program header that explains some stuff about the program */
/* itself and may have a long copyright clause in addition. Blah, blah, */
/* blah. Blah, blah, blah, blah. */
/* */
/* This program is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/* This software is dedicated to my dear, sweet mother. */
/*************************************************************************/
#include <stdio.h>
int main() { printf("Real code begins on line 20.\n"); return 0;}
If you happen to be using vim (and not plain vi/ex), you could use something like this script in stead/addition.
Tee hee... when I posted in this thread, I knew it would grow quickly.
I love vi, my .exrc is pretty huge (I won't give the exact amount of lines, or post all of the aliases and functions, that would just feed the fire ) ... there are as many ways to do <insert action here> as there are people to do them.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.