If you want to do this with a single command, I would recommend the following:
:%s/.*/\=' ['.(line('.')-1).']="'.submatch(0).'" \'
This uses the
\= to evaluate the following strings joined together (remember,
'.' means concatenation in vimscript):
line('.') returns the current line number, and
submatch(0) is like
\0 in regex (it captures the entire text).
However, if I were the one editing this, I'd probably do it in normal mode (assuming vim 7.4+). For example:
<C-v>GI [-1]="<esc>gvwwg<C-a>gv$A" \<esc>
Rather than explaining each part of this, it would be easier to just type these out and see the effects.
Of course, neither of these solutions will work if you are trying to do this to only certain lines in the buffer, rather than the whole thing. In that case, you could modify each one. For example, the first one could be modified by changing
:a,b, where a and b are you start/end lines. And then change
The second solution would just require changing your visual block selection, so not using
As a side note,
is unnecessary because
:g/^/s/^ is exactly the same as