Vim: replacing start and end of a visual char, line or block

Posted by gattu marrudu on Stack Overflow See other posts from Stack Overflow or by gattu marrudu
Published on 2011-11-28T17:46:36Z Indexed on 2011/11/28 17:56 UTC
Read the original article Hit count: 188

Filed under:
|
|

I am trying to find a shortcut to place a custom comment sequence on my code, e.g.:

/*
start of comment
blah
end of comment
/**/

(it is easier to void the comment by just adding a / to the beginning)

I would like to do this in Vim by selecting a visual line, block or char and adding '/' characters at the beginning of the block and '/*/' at the end, plus newlines.

After selecting some lines (Shift-V) I tried this:

'<,'>s/\(.*\)/\/*\r\1\r\/**\//

But it adds the comment chars at EACH newline.

How can I only apply the substitution at the beginning and end of the selected range?

Thanks gm

© Stack Overflow or respective owner

Related posts about vim

Related posts about visual