user1030470
user1030470

Reputation: 13

Looking for a vim command to insert a character on certain lines

There may or may not have been asked before, but I don't know enough about vim to be able to look. How can I add add single quotes (') 5 characters into the line and at the end of every line that begins with a (-)

An example from the file is

       want quotes
    here     &      here        
     v               v
    - essentials.help
    - essentials.helpop
    - essentials.list
    - essentials.motd
    - essentials.rules
    - essentials.spawn
    - groupmanager.notify.self

Upvotes: 1

Views: 73

Answers (1)

Greg Hewgill
Greg Hewgill

Reputation: 992857

You could do something like:

:%s/^    -\(.*\)/    -'\1'/

Adjust the exact number of spaces you need as required.

This searches for the start of a line ^, then four spaces, a dash, and then uses a capturing group to capture all the characters to the end of the line. Then it's replaced with four spaces, a dash, a single quote, \1 is the contents of the capturing group, then a final single quote.

The leading % applies this command to all lines in the file.

Upvotes: 1

Related Questions