gattu marrudu
gattu marrudu

Reputation: 257

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

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

Upvotes: 3

Views: 177

Answers (2)

ib.
ib.

Reputation: 28954

Consider using the following substitution command.

:'<s~^~/*\r~|'>s~$~\r/**/~

Upvotes: 1

vharavy
vharavy

Reputation: 4991

Try this one :'<,'>s-\(\_.*\)-/*\r\1\r/**/-

Update: I believe this is not the best way of achieving the result you want. I recommend you to read some information about '< and '> marks. With this mark the commenting can be implemented more efficiently. Also, there is lot of ready solutions for this task.

Upvotes: 0

Related Questions