0

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]`
Sylvester Kruin
  • 3,294
  • 5
  • 16
  • 39
monte
  • 1,482
  • 1
  • 10
  • 26

3 Answers3

3

Select the lines (eg, V4j) and use:

s/$/`/

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

s/ *$/`/

or similar

William Pursell
  • 204,365
  • 48
  • 270
  • 300
0

The command you are asking about:

<C-v>4jI`

is actually the one you used to obtain the initial state of this question:

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

To obtain this from the previous state:

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

you did the following with the cursor on the last character of the first line:

<C-v>4jA`

which is the actual command you should have mentioned in your question.

Note that you only have three lines, here, so it should have actually been:

<C-v>2jI`

for the first step, and:

<C-v>2jA`

for the second step.

Now that that is out of the way, you should be able to obtain the desired result with the following command, executed with the cursor on the first character of the first line:

<C-v>2j$A`

Note the $, which extends the visual area to the end of each concerned line. That is what allows you to insert something at the end of each line.

cv

Note also that:

<C-v>2jI`
<C-v>2j$A`

is not really an efficient method for reaching your initial goal. Using a simple substitution like:

:,+2s/.*/`&`

would have been a much better approach.

romainl
  • 186,200
  • 21
  • 280
  • 313
0

After selecting the lines you can use:

:normal A`

Note that the range '<,'> will be automatically added. See :help :normal-range

Jogusa
  • 5,530
  • 5
  • 24
  • 23