I find it sometimes useful to add a certain string to the beginning of a line, and sometimes I would like to do this to a few lines, and I don't like moving to each line and change it. Assuming I know how to select the lines that interest me in Visual mode, how can I add the prefix?
What I do to achieve this is to make a visual rectangular selection with Ctrl-V at the place where I want to add the prefix, and once all lines are selected, just press I (that's a capital i) and type in the text. When exiting insert mode the text will be copied to all the lines.
This is the sequence in images:
- Visual selection of the place of insertion
- Type in the text
- Back to normal mode and the insertion is done
Note that this works anywhere, not only at the beginning of the line.
Usually it goes like this for me:
Esc + Shift-V + select lines + : s//prefix[Enter]
Edit: Why I like it is that it's still quick and when sometimes you want to use something more then this is nice base to start from, like next adding line numbers, ore expanding regex further
Assuming you'd like to add prefix to 5 lines at the beginning of the line, then you can use Search and replace:
or at the end of the lines: