1

when I need to insert some same text in several lines, normally I would switch to VISUAL-BLOCK and insert the desired text. (CTRL+V, motions, SHIFT+I) but as in the default behavior of vim, It only give the first line of visual feedback before returning to NORMAL mode (as in the second image). Is there any option or way I could achieve the result as stated in the title of this question?

enter image description here enter image description here enter image description here

Bi Ao
  • 704
  • 5
  • 11
  • Does this answer your question? [Vim: insert the same characters across multiple lines](https://stackoverflow.com/questions/9549729/vim-insert-the-same-characters-across-multiple-lines) – Tigger Jan 18 '20 at 06:59
  • You could try the plugin [vim-multiple-cursors](https://github.com/terryma/vim-multiple-cursors) – builder-7000 Jan 18 '20 at 07:18

2 Answers2

2

I don't know why you feel you need to stay in visual-block mode; you could accomplish this in normal mode in multiple ways.

Label all the lines you need as 0 NULL, and then use visual-block mode to highlight the column of zeros; then, use g<C-a> to increment each line.

You could also use a :global command like :g/\v^\d+/normal A<Tab>NULL.

There's probably also a solution with a macro, but you see where I'm going with this. It's an easily-scriptable task.

Hari Amoor
  • 442
  • 2
  • 7
1

Insert the first null with A + literal tab + NULL like this:

ID  MEMBER_TYP
--------------
1   NULL
2
3

If you are using relative number:

:4,+14 normal .

More about Relative Numbers: If you are at the line 4 and the last relative number shows 13 you can type:

14:   ..................... shortcut to :.,.+13

After typing 14: just type norm . and hit Enter

Starting from next line until the end:

:+1,$ norm .

A third way:

:.,$s/\v\d+/&   NULL

NOTE: Again the tab must be typed literally

:.,$ ..................... from this line to the end
\v ....................... very magic
\d+ ...................... match digits
& ........................ matched pattern

Maybe the best way:

ID  MEMBER_TYP
--------------
1
2
3

At the first number, 1

Ctrl-v ........... start visual block
} ................ extends selection till the end
A ................ starts insert at the end of line
<TAB> ............ literal tab
SergioAraujo
  • 11,069
  • 3
  • 50
  • 40