Skip to main content
added 219 characters in body
Source Link
Sergiy Kolodyazhnyy
  • 16.9k
  • 12
  • 58
  • 111

VIM solutionsolutions

There's two solutions: one is via automating Ctrla keypress over a selection, second is via executing a pattern replacement with submatch(0)+1 over the selection. First the key automation.

Start by creating your list:

1. foo
2. bar 100%
3. kittens
4. eat cake
5. unicorns
6. rainbows

Insert an entry

1. foo
2. bar 100%
3. kittens
4. eat cake
4. sunshine
5. unicorns
6. rainbows

Position 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+A

What 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 change

Solution in action:

Before

enter image description here

After

enter image description here


Another way would be to select everything from the first repeated number like before( Shiftv, then G ), and go into command mode to execute:

:'<,'>s/\v(^\d+)\./\=(submatch(0)+1).'.'/ 

VIM solution

Start by creating your list:

1. foo
2. bar 100%
3. kittens
4. eat cake
5. unicorns
6. rainbows

Insert an entry

1. foo
2. bar 100%
3. kittens
4. eat cake
4. sunshine
5. unicorns
6. rainbows

Position 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+A

What 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 change

Solution in action:

Before

enter image description here

After

enter image description here


Another way would be to select everything from the first repeated number like before( Shiftv, then G ), and go into command mode to execute:

:'<,'>s/\v(^\d+)\./\=(submatch(0)+1).'.'/ 

VIM solutions

There's two solutions: one is via automating Ctrla keypress over a selection, second is via executing a pattern replacement with submatch(0)+1 over the selection. First the key automation.

Start by creating your list:

1. foo
2. bar 100%
3. kittens
4. eat cake
5. unicorns
6. rainbows

Insert an entry

1. foo
2. bar 100%
3. kittens
4. eat cake
4. sunshine
5. unicorns
6. rainbows

Position 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+A

What 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 change

Solution in action:

Before

enter image description here

After

enter image description here


Another way would be to select everything from the first repeated number like before( Shiftv, then G ), and go into command mode to execute:

:'<,'>s/\v(^\d+)\./\=(submatch(0)+1).'.'/ 
added 232 characters in body
Source Link
Sergiy Kolodyazhnyy
  • 16.9k
  • 12
  • 58
  • 111

VIM solution

Start by creating your list:

1. foo
2. bar 100%
3. kittens
4. eat cake
5. unicorns
6. rainbows

Insert an entry

1. foo
2. bar 100%
3. kittens
4. eat cake
4. sunshine
5. unicorns
6. rainbows

Position 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+A

What 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 change

Solution in action:

Before

enter image description here

After

enter image description here


Another way would be to select everything from the first repeated number like before( Shiftv, then G ), and go into command mode to execute:

:'<,'>s/\v(^\d+)\./\=(submatch(0)+1).'.'/ 

VIM solution

Start by creating your list:

1. foo
2. bar 100%
3. kittens
4. eat cake
5. unicorns
6. rainbows

Insert an entry

1. foo
2. bar 100%
3. kittens
4. eat cake
4. sunshine
5. unicorns
6. rainbows

Position 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+A

What 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 change

Solution in action:

Before

enter image description here

After

enter image description here

VIM solution

Start by creating your list:

1. foo
2. bar 100%
3. kittens
4. eat cake
5. unicorns
6. rainbows

Insert an entry

1. foo
2. bar 100%
3. kittens
4. eat cake
4. sunshine
5. unicorns
6. rainbows

Position 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+A

What 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 change

Solution in action:

Before

enter image description here

After

enter image description here


Another way would be to select everything from the first repeated number like before( Shiftv, then G ), and go into command mode to execute:

:'<,'>s/\v(^\d+)\./\=(submatch(0)+1).'.'/ 

VIM solution

Start by creating your list:

1. foo
2. bar 100%
3. kittens
4. eat cake
5. unicorns
6. rainbows

Insert an entry

  1. foo
  2. bar 100%
  3. kittens
  4. eat cake
  5. sunshine
  6. unicorns
  7. rainbows
1. foo
2. bar 100%
3. kittens
4. eat cake
4. sunshine
5. unicorns
6. rainbows

Position your cursor onto 4. sunshine and from command mode press Shiftshift + v v, then Shiftshift + g 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 Ctr-V Ctrl-A

norm Ctrl+V Ctrl+A

What 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 keypreskeypress Ctrl-A , and Ctrl-A by default increments the number under cursor. You will see the numbers change

Solution in action:

Before

enter image description here

After

enter image description here

VIM solution

Start by creating your list:

1. foo
2. bar 100%
3. kittens
4. eat cake
5. unicorns
6. rainbows

Insert an entry

  1. foo
  2. bar 100%
  3. kittens
  4. eat cake
  5. sunshine
  6. unicorns
  7. rainbows

Position your cursor onto 4. sunshine and from command mode press Shift + v , then Shift + g . This is visual selection till the end of file.

Press : to enter command mode, and you will see this: `:'<,'>`` . Now type in the following:

norm Ctr-V Ctrl-A

What 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 keypres Ctrl-A , and Ctrl-A by default increments the number under cursor. You will see the numbers change

Solution in action:

Before

enter image description here

After

enter image description here

VIM solution

Start by creating your list:

1. foo
2. bar 100%
3. kittens
4. eat cake
5. unicorns
6. rainbows

Insert an entry

1. foo
2. bar 100%
3. kittens
4. eat cake
4. sunshine
5. unicorns
6. rainbows

Position 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+A

What 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 change

Solution in action:

Before

enter image description here

After

enter image description here

Source Link
Sergiy Kolodyazhnyy
  • 16.9k
  • 12
  • 58
  • 111
Loading