Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the easiest way in Vim to go from:




For a list of arbitrary length?

share|improve this question
up vote 3 down vote accepted

You can add <table> and </table> manually: ggO<table>[ESC]YGpa/[ESC] Where [ESC] is the top-left key on your keyboard +)

  1. gg - go to the top of the file
  2. O - add new line above the current
  3. <table> - write <table>
  4. [ESC] - back to the command mode
  5. Y - yank current line
  6. G - go to the end of the file
  7. p - paste yanked line below the current
  8. a - begin insert mode and start inserting after current symbol
  9. / - add / symbol
  10. [ESC] - back to the command line

Now u can record a short vim macros to repeat another set of command multiple times:

:2[ENTER]qqO<tr>[ESC][DOWN]I<td>[ESC]A</td>[ESC][DOWN] I<td>[ESC]A</td>[ESC]o</tr>[ESC][DOWN]q

yep, now u can just repeat @q multiple times...(e.g. 11@q)

  1. :2 - go to the second line in the file
  2. qq - start recording macros in 'q' register
  3. O - add new line above the current
  4. <tr> - add <tr>
  5. [ESC][DOWN] - you know =)
  6. I - go to the begining of the line and start the insert mode
  7. <td> - write <td>
  8. [ESC] - ...
  9. A - go to the line end and start the insert mode
  10. </td> - ...
  11. [ESC][DOWN]
  12. repeat 6-10
  13. [ESC]
  14. o - add line below current and start the insert mode
  15. </tr> - ...
  16. [ESC][DOWN]q - end macros recording
share|improve this answer
im accepting this, though the full regex solution would be interesting as well – Sam Saffron Feb 15 '10 at 9:19

May be you are looking for zen-coding for vim.

share|improve this answer
+1, might not be exactly what the OP is looking for, but this looks awesome! – technomalogical Feb 15 '10 at 14:41
+1 zen coding suits this job . it'll increase your speed in coding :) – nXqd Feb 19 '10 at 3:20

I know you're probably thinking of some clever solution using macros, but I'd let my fingers do the walking (since you're not likely to have an HTML table hundreds of lines long):

For each line of the file, replace the beginning of line with <td> And for each line, replace the end of line with </td>


goto the first line and insert


Yank those lines, press down-arrow until you're at the next insertion point and press p Continue to the bottom of the file, pressing p every two lines. There's a simple kind of rhythm here that I like to use: down, down, p, down, down, p, etc.

Change the last line to


Go back to the top and change the first line to


Obviously, I haven't tried this (and I concede that macros might be easier for some)

share|improve this answer

You must log in to answer this question.

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