2

I'm attempting to add a column to an HTML table using vim so I need to add a pair of <td> tags the line before each </tr>. So far I have

:186,$s/ <\/tr>/<td><\/td> \n <\/tr>/g
but vim shows ^@ instead of making a new line for the closing tr tag. Is there any way around that?

1 Answer 1

4

Yes, you need to use \r instead of \n in the replacement part, a quirk of Vim's :s command. And you can further simplify the command by using a different separator, e.g. #, and by referring to the match via &:

:186,$s# </tr>#<td></td> \r&#g
2
  • Thanks! I'm a little confused because I thought that \n was the linux newline character and \r\n was for windows. Also, what does it mean to "refer to the match with &?
    – Yitzchak
    Jul 10, 2014 at 15:25
  • 1
    That's explained at :h s/\r and :h s/\&, resp. The & contains the match, i.e. </tr>, so you don't need to repeat it. You could also use an assertion with \zs, but that's even more advanced... Jul 10, 2014 at 15:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .