Reputation: 113335
I have the following file content opened in VIM:
123
234
345
546
567
678
789
~
~
~
~
~
I want to add ;
to end of the each line. For that I go to the end of the first line and use a vertical selection pressing CTRL + v
.
I select the first 7 lines (the lines with numbers) and then I press SHIFT + I
and move the cursor to the end of the line. I write ;
and then I press Esc
.
The result is this:
123;
2334
3435
5436
5637
6738
7839
...while I expected:
123;
233;
343;
543;
563;
673;
783;
Why is this happening and how can I solve it?
Note that this is just an example how to reproduce the issue. I know that I can use a regexp or a macro to do the same thing, but I want to find the answer to the questions above.
Upvotes: 0
Views: 75
Reputation: 172510
Shift + I is for prepending at the beginning of the visual blockwise selection; by moving the cursor to the end, you've ruined it! (Vim doesn't seem to recognize that you've moved the cursor, and thinks the 3
on which you've started the edit is what you've entered. It's debatable whether this is a bug.)
What you need to use is Shift + A, which appends at the end of all selected lines.
Upvotes: 2
Reputation: 23058
Use the following command:
:1,7 s/$/;/
Edit: Change Shift+I into Shift+A can achieve your purpose.
Upvotes: 2
Reputation: 2507
You've only told vim to replace the first occurrence. Instead, go to the end of line 1 and press ctrl-v
and select to the bottom of the file. Then press :
to move to the command line. This will now show :'<,'>
. If you type s/$/;/g
here and hit return, you will get a semi-colon at the end of every selected line.
Hope this helps.
Upvotes: 1