Search code examples
vim

vim editing multiple lines to add text at the end of text


I have a following block of text.

`[1,2,3,4]
`[1,2,4]
`[1,2]

I want to add a backtick ( ` ) at the end of each line. However when I try the following key combination <C-v>4jI, it does add the backtick at the end of line but there is some space introduced. How do I add it at the end of the text?

With the command C-v4jI, the output is like this:

`[1,2,3,4]`
`[1,2,4]  `
`[1,2]    `

What I want is like this:

`[1,2,3,4]`
`[1,2,4]`
`[1,2]`

Solution

  • Select the lines (eg, V4j) and use:

    s/$/`/
    

    If there is trailing whitespace already present, you may need:

    s/ *$/`/
    

    or similar