Reputation: 83
I have a dataset like by inserting a new column of data between 1st column
M1 M2 M3 M4
G1 1 2 3 4
G2 4 3 2 1
...
G120 1 3 4 2
I would like to modify dataset with another column of data in vim to
M1 M2 M3 M4
G1 1 1 2 3 4
G2 1 4 3 2 1
...
G120 1 1 3 4 2
Upvotes: 3
Views: 2659
Reputation: 16667
Vim's blockwise visual mode, ctrl-v
, is probably the best way to do this.
In particular, you should use "Visual-block Insert" (vim help: :help v_b_I
)
With your example, with the cursor at |1|
in normal mode:
M1 M2 M3 M4
G1 |1| 2 3 4
G2 4 3 2 1
...
G120 1 3 4 2
Do the following:
ctrl-v
- start visual blockwise selection3j
- extend selection 3 lines down (can substitute any other movement command here)I
- begin block insert mode1<space><space><space><space><space>
- the text you want inserted every lineEsc
or ctrl-[
(its synonym) - complete the visual-block insertVisual block insert can also be used to indent/unindent multiple lines, append text to every line (even if they don't end on the same column), etc, etc.
Upvotes: 2
Reputation: 6333
i assume you use \t to align your text. then regex can be used
:%s/^\(G\d\+\)/\1\t1/
Upvotes: 2