Friday, February 26, 2010

vi, search string and comment line howto?

Hello, I can't figure out the syntax to search for a certain string and then
comment out that line. I know you can have multiple commands on a single
line, but I can't figure it out. As an example I have a "file" with the
following contents:

line 1 and stuff
line 2 contains my_string
line 2 and stuff

Now I want to vi the "file" and comment out the line containing "my_string"
by running the following commands:
vi file #to start editing "file"
/my_string #to search for the line I want to comment, containing
"my_string"
I# #to append a comment (#) to the beginning of the
current line
:wq #to write and quit

I should be able to string all the above commands together separated by a
pipe:
vi -c "/my_string | I# | :wq" file #give all the editing
commands to vi on the command line

vi file
/my_string | I# | :wq #or open the file in
vi and then enter the commands

but the above fails with: E486: Pattern not found: my_string | I# | wq

so, what am I doing wrong, anyone know how to accomplish searching for a
particular string and then comment out the line that it's on? Thanks.

--
View this message in context: http://old.nabble.com/vi%2C-search-string-and-comment-line-howto--tp27724017p27724017.html
Sent from the Vim - General mailing list archive at Nabble.com.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment