Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

vim
community creator

How to prepend a set of lines with Vim

Anjana Shankar

Have you ever faced a situation where you just wanted to have a set of characters prepended to a set of lines in one of your files, and wished that there was an easy way to do it? Well, Vim gives you a very simple way of doing this.

First, let’s create a file with some contents. I have a main.txt with the following contents:

Hi
This is
Testing 
insertion of
word at the
beginning of all lines

Now, do the following and see what happens:

  1. Use Ctrl+V to select the first column of text in the lines you want to comment on.
  2. Then, hit Shift+I and type the text you want to insert.
  3. Finally, hit Esc, wait 1 second, and the inserted text will appear on every line.

RELATED TAGS

vim
community creator
RELATED COURSES

View all Courses

Keep Exploring