Using visual block mode:
y3j <Cv>3j I0<Esc> '> p <Cv>3j I1<Esc>
You can start with Appendix 1 and use P to skip '> :
y3j <Cv>3j I1<Esc> P <Cv>3j I0<Esc>
Using Ex commands only:
:,+3y<CR> :,+3norm! I0<CR> :put :<Up> "use commandline history to save some typing <Backspace>1<CR>
Using a combination of substitution and normal mode commands:
y3j :,+3s/^/0<CR> p :<Up> <Backspace>1<CR>
If you do so much, writing this in a macro is probably the best strategy. At this point, how the actual filling is done is actually not relevant, as the only thing you do is @x , and the macro is likely to be instantaneous anyway.
What you do while recording doesn't really matter, here is an example:
qx y3j :,+3s/^/0<CR> p :,+3s/^/1<CR> q
Suppose you have this:
[0]0 01 10 11
Pressing @x results in:
000 001 010 011 100 101 110 111
Your macro is stored in register x and will be available for the next Vim session.
And I'm sure someone can come up with a good liner.
change
Step-by-step explanation of the macro above:
qx , start writing to register x (this can be any available register).
y3j , y3j current line and the next three.
: , no explanation is required.
,+3 , this is the range we are working on. A more correct way to determine this range would be .,+3 . The start line and end line of the range are separated by a coma.
The start line is the current line that we can omit to preserve some typing, so we are left with a coma, followed by the end line, expressed relative to the current line +3 .
s/^/0<CR> , this is a simple substitution.
^ in the search pattern means "start of line". It does not match the first character, so it is great for situations like this, where we want to add something to the string.
So basically we add a line with 0 . It may be what you want.
When you perform a range swap, substitution is performed on each row of the range. Here we have four lines, so each line is added using 0 .
<CR> , is, well ... the <Enter> key used to perform the substitution.
P , insert the four lines that we pulled before the current line.
:,+3s/^/1<CR> , as before, but with 1 .
q , completion of recording.
And to answer your comment, here is how you do it:
00 01 10 11
in it:
00 0.0 01 0.0 10 0.0 11 0.0
You need to use another "anchor". ^ is the "beginning of the line", $ is the "end of the line", so the substitution becomes:
:,+3s/$/ 0.0
source share