I have a text file of numbered entries:1. foo2. bar 100%3. kittens4. eat cake5. unicorns6. rainbowsand so on up to some large number. Then after an empty line, a new block starts from 1.I insert a new entry, replacing, say, 4. and I need to renumber all the subsequent entries in the block:1. foo2. bar 100%3. kittens4. sunshine <5. eat cake6. unicorns7. rainbows
Re-number a list when a new entry is inserted
text processing
VIM solutionStart by creating your list:1. foo2. bar 100%3. kittens4. eat cake5. unicorns6. rainbowsInsert an entry 1. foo2. bar 100%3. kittens4. eat cake4. sunshine5. unicorns6. rainbowsPosition your cursor onto 4. sunshine and from command mode press shift + v, then shift + g . This is visual selection till the end of file. You can also move the cursor to the end of a block in the usual ways.Press : to enter command mode, and you will see this: :'<,'>  . Now type in the following:norm Ctrl+V Ctrl+AWhat Ctrl-v and ctrl-A do, is they allow you to enter exact key, so it will change into ^A , highlighted. This is basically saying for all lines selected, execute in normal mode keypress Ctrl-A , and Ctrl-A by default increments the number under cursor.  You will see the numbers changeSolution in action:BeforeAfter