1

Say I have a paragraph like this

line1
line2
line3

I want to select all and then transform like this

:start
line1
:end

:start
line2
:end

:start
line3
:end

Don't ask me why, we have some strange text transformation requirements. I could do it with Python but how can I do this in Vim.

I know I would start by selecting the block via V

1 Answer 1

5

The classic :s command can do stuff like this easily. e.g. type

:s/.*/:start\r&\r:end\r/

It looks like

:'<,'>s/.*/:start\r&\r:end\r/

on the command line if you select the area first, because '< and '> denote the visually selected range.

.* matches the entire line, \r is inserting newline, the & in the pattern represents the matched text (:h s/\r, :h s/\&)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.