How do I create a macro that converts lines to a numbered list?
Answer
qa I1. <Esc>j q
Explanation
This simple macro inserts a list number prefix at the beginning of each line. Combined with visual block increment, it creates proper numbered lists.
How it works
qa— start recordingI1.— insert1.at the beginning of the line<Esc>— return to normal modej— move to the next lineq— stop recording
Example
apple
banana
cherry
After qa I1. <Esc>jq and 2@a, then fix numbers with visual block and g<C-a>.
Tips
- Use the counter technique for proper auto-numbering
- Or apply
1.to all lines then useg<C-a>to fix numbers - For markdown lists, use
-instead of1. - Combine with
:g/pattern/normal @afor selective application