Visual Block Mode edit with sequential number [duplicate]How to write incremental lines in Vim?Vertically rotate visual blockIs there a command to enter Visual Block mode?Can I select and edit specific positions in lines while in visual block mode?extra newlines when pasting altered string in visual block modePassing visual range to a :command as its argumentVim ^V Visual Block mode not workingWould you ever want to start recording a macro from the quickfix window?combining two map commandsBind visual mode 'I' and 'A' to always use visual block mode before insertingJump to bottom of block in Visual Block mode
Why are C64 games inconsistent with which joystick port they use?
How do I know what is the origin IP if I ping from a router to a host of an external network in packet tracer?
Who will lead the country until there is a new Tory leader?
Why do Windows registry hives appear empty?
Boss wants me to falsify a report. How should I document this unethical demand?
How to respond to an upset student?
I think I may have violated academic integrity last year - what should I do?
NIntegrate doesn't evaluate
Wireless Multipoint Bridging / Backhaul Gateway Antenna and AP Selection
Does the unit of measure matter when you are solving for the diameter of a circumference?
How strong are Wi-Fi signals?
Looking for a soft substance that doesn't dissolve underwater
How to know if a folder is a symbolic link?
the meaning of 'carry' in a novel
Would jet fuel for an F-16 or F-35 be producible during WW2?
Defining the standard model of PA so that a space alien could understand
Why does a perfectly-identical repetition of a drawing command given within an earlier loop 𝘯𝘰𝘵 produce exactly the same line?
Simple fuzz pedal using breadboard
What is the object moving across the ceiling in this stock footage?
Why do most published works in medical imaging try to reduce false positives?
My employer faked my resume to acquire projects
Why colon to denote that a value belongs to a type?
Is the Starlink array really visible from Earth?
Why did David Cameron offer a referendum on the European Union?
Visual Block Mode edit with sequential number [duplicate]
How to write incremental lines in Vim?Vertically rotate visual blockIs there a command to enter Visual Block mode?Can I select and edit specific positions in lines while in visual block mode?extra newlines when pasting altered string in visual block modePassing visual range to a :command as its argumentVim ^V Visual Block mode not workingWould you ever want to start recording a macro from the quickfix window?combining two map commandsBind visual mode 'I' and 'A' to always use visual block mode before insertingJump to bottom of block in Visual Block mode
This question already has an answer here:
How to write incremental lines in Vim?
4 answers
Suppose I'd like to create a list
- "1"
- "2"
- "3"
what Is the smartest way to create such?
My attempt would be to i- "1"
ESCyypp to get
- "1"
- "1"
- "1"
and then jump to the second line's 1 r2jr3
BUT: doing this for a list of e.g. 100 (also thinking about the second digit) is not what I want to do with technique above...
I am using nvim v0.3.5 von archLinux, but i don't think, that that does matter.
visual-mode macro visual-block line-numbers
New contributor
marked as duplicate by Hotschke, Rich, statox♦ May 21 at 9:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to write incremental lines in Vim?
4 answers
Suppose I'd like to create a list
- "1"
- "2"
- "3"
what Is the smartest way to create such?
My attempt would be to i- "1"
ESCyypp to get
- "1"
- "1"
- "1"
and then jump to the second line's 1 r2jr3
BUT: doing this for a list of e.g. 100 (also thinking about the second digit) is not what I want to do with technique above...
I am using nvim v0.3.5 von archLinux, but i don't think, that that does matter.
visual-mode macro visual-block line-numbers
New contributor
marked as duplicate by Hotschke, Rich, statox♦ May 21 at 9:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to write incremental lines in Vim?
4 answers
Suppose I'd like to create a list
- "1"
- "2"
- "3"
what Is the smartest way to create such?
My attempt would be to i- "1"
ESCyypp to get
- "1"
- "1"
- "1"
and then jump to the second line's 1 r2jr3
BUT: doing this for a list of e.g. 100 (also thinking about the second digit) is not what I want to do with technique above...
I am using nvim v0.3.5 von archLinux, but i don't think, that that does matter.
visual-mode macro visual-block line-numbers
New contributor
This question already has an answer here:
How to write incremental lines in Vim?
4 answers
Suppose I'd like to create a list
- "1"
- "2"
- "3"
what Is the smartest way to create such?
My attempt would be to i- "1"
ESCyypp to get
- "1"
- "1"
- "1"
and then jump to the second line's 1 r2jr3
BUT: doing this for a list of e.g. 100 (also thinking about the second digit) is not what I want to do with technique above...
I am using nvim v0.3.5 von archLinux, but i don't think, that that does matter.
This question already has an answer here:
How to write incremental lines in Vim?
4 answers
visual-mode macro visual-block line-numbers
visual-mode macro visual-block line-numbers
New contributor
New contributor
New contributor
asked May 20 at 15:02
JoelJoel
1283
1283
New contributor
New contributor
marked as duplicate by Hotschke, Rich, statox♦ May 21 at 9:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Hotschke, Rich, statox♦ May 21 at 9:19
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Depending on your usecase the following might be useful:
Create the entries all with the number "1":
- "1"
- "1"
- "1"
- "1"
Then go to the second "1" and press V to start line-wise visual. Then move down to the last "1". So now all but the first "1" is selected.
Now hit gCtrl-a and you get
- "1"
- "2"
- "3"
- "4"
See :help v_g_CTRL-A
Update: What if a I need a new number "3" and all following should be increased by one?
First insert the new line:
- "1"
- "2"
- "3"
- "3"
- "4"
Then go to the second "3", hit V and move down to the end of the list. Now hit Ctrl-a (without leading g
) and the selected numbers are increased by one.
You get:
- "1"
- "2"
- "3"
- "4"
- "5"
2
and additional +1 for the:help v_g_CTRL-A
– Joel
May 20 at 15:34
2
I had no clue ofv_g_CTRL-A
, brilliant! you have my vote.
– padawin
May 20 at 15:45
Note thatv_g_CTRL-A
is only available since vim 8.1.
– TonioElGringo
May 21 at 10:51
add a comment |
Here's a shorter macro version.
First write a single line with the contents
- "1"
Then type the following:
qqyypCtrl-Aq98@q
qq—start recording
yyp—Duplicate the line
Ctrl-A—Increment the number
q—End the recording
98@q—Replay 98 times
add a comment |
I would do it as follow:
- Somewhere in your file (before where you want your list), add a line with the first number - 1 (most likely 0),
- Make a mark at this place (
ma
) - Make an empty line where you want your list and make another mark there (
mb
)
Your file would, at this point, look like this (The lines 1 and 2 don't matter, they are just here to say where the marks are):
- Record the following macro:
qq // Start the macro in register q
`a // go to mark a
CTRL-a // Increase the number
yiw // Copy the number
`b // Go to mark b
i- " // Go in insert mode, insert - "
<esc>p // leave the insert mode and paste the number
A"<CR><esc> // Closes the quote, add a new line and leave the insert mode
mb // Update the mark b to be here
q // Stop recording the macro
100@q // Run the macro 100 times
You can delete the line where the mark a is, as it was just to store the counter.
And voila.
I like the idea of using a variable. Is there an option to save (and increase) this variable inside a register? That would make the macro much shorter.
– Joel
May 20 at 15:17
1
I am not sure it is easily possible (without using a:
command, which is fine too, but I don't think that would make the macro simpler). Maybe someone will have a suggestion to improve it?
– padawin
May 20 at 15:19
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Depending on your usecase the following might be useful:
Create the entries all with the number "1":
- "1"
- "1"
- "1"
- "1"
Then go to the second "1" and press V to start line-wise visual. Then move down to the last "1". So now all but the first "1" is selected.
Now hit gCtrl-a and you get
- "1"
- "2"
- "3"
- "4"
See :help v_g_CTRL-A
Update: What if a I need a new number "3" and all following should be increased by one?
First insert the new line:
- "1"
- "2"
- "3"
- "3"
- "4"
Then go to the second "3", hit V and move down to the end of the list. Now hit Ctrl-a (without leading g
) and the selected numbers are increased by one.
You get:
- "1"
- "2"
- "3"
- "4"
- "5"
2
and additional +1 for the:help v_g_CTRL-A
– Joel
May 20 at 15:34
2
I had no clue ofv_g_CTRL-A
, brilliant! you have my vote.
– padawin
May 20 at 15:45
Note thatv_g_CTRL-A
is only available since vim 8.1.
– TonioElGringo
May 21 at 10:51
add a comment |
Depending on your usecase the following might be useful:
Create the entries all with the number "1":
- "1"
- "1"
- "1"
- "1"
Then go to the second "1" and press V to start line-wise visual. Then move down to the last "1". So now all but the first "1" is selected.
Now hit gCtrl-a and you get
- "1"
- "2"
- "3"
- "4"
See :help v_g_CTRL-A
Update: What if a I need a new number "3" and all following should be increased by one?
First insert the new line:
- "1"
- "2"
- "3"
- "3"
- "4"
Then go to the second "3", hit V and move down to the end of the list. Now hit Ctrl-a (without leading g
) and the selected numbers are increased by one.
You get:
- "1"
- "2"
- "3"
- "4"
- "5"
2
and additional +1 for the:help v_g_CTRL-A
– Joel
May 20 at 15:34
2
I had no clue ofv_g_CTRL-A
, brilliant! you have my vote.
– padawin
May 20 at 15:45
Note thatv_g_CTRL-A
is only available since vim 8.1.
– TonioElGringo
May 21 at 10:51
add a comment |
Depending on your usecase the following might be useful:
Create the entries all with the number "1":
- "1"
- "1"
- "1"
- "1"
Then go to the second "1" and press V to start line-wise visual. Then move down to the last "1". So now all but the first "1" is selected.
Now hit gCtrl-a and you get
- "1"
- "2"
- "3"
- "4"
See :help v_g_CTRL-A
Update: What if a I need a new number "3" and all following should be increased by one?
First insert the new line:
- "1"
- "2"
- "3"
- "3"
- "4"
Then go to the second "3", hit V and move down to the end of the list. Now hit Ctrl-a (without leading g
) and the selected numbers are increased by one.
You get:
- "1"
- "2"
- "3"
- "4"
- "5"
Depending on your usecase the following might be useful:
Create the entries all with the number "1":
- "1"
- "1"
- "1"
- "1"
Then go to the second "1" and press V to start line-wise visual. Then move down to the last "1". So now all but the first "1" is selected.
Now hit gCtrl-a and you get
- "1"
- "2"
- "3"
- "4"
See :help v_g_CTRL-A
Update: What if a I need a new number "3" and all following should be increased by one?
First insert the new line:
- "1"
- "2"
- "3"
- "3"
- "4"
Then go to the second "3", hit V and move down to the end of the list. Now hit Ctrl-a (without leading g
) and the selected numbers are increased by one.
You get:
- "1"
- "2"
- "3"
- "4"
- "5"
edited May 20 at 15:50
answered May 20 at 15:27
RalfRalf
4,1551319
4,1551319
2
and additional +1 for the:help v_g_CTRL-A
– Joel
May 20 at 15:34
2
I had no clue ofv_g_CTRL-A
, brilliant! you have my vote.
– padawin
May 20 at 15:45
Note thatv_g_CTRL-A
is only available since vim 8.1.
– TonioElGringo
May 21 at 10:51
add a comment |
2
and additional +1 for the:help v_g_CTRL-A
– Joel
May 20 at 15:34
2
I had no clue ofv_g_CTRL-A
, brilliant! you have my vote.
– padawin
May 20 at 15:45
Note thatv_g_CTRL-A
is only available since vim 8.1.
– TonioElGringo
May 21 at 10:51
2
2
and additional +1 for the
:help v_g_CTRL-A
– Joel
May 20 at 15:34
and additional +1 for the
:help v_g_CTRL-A
– Joel
May 20 at 15:34
2
2
I had no clue of
v_g_CTRL-A
, brilliant! you have my vote.– padawin
May 20 at 15:45
I had no clue of
v_g_CTRL-A
, brilliant! you have my vote.– padawin
May 20 at 15:45
Note that
v_g_CTRL-A
is only available since vim 8.1.– TonioElGringo
May 21 at 10:51
Note that
v_g_CTRL-A
is only available since vim 8.1.– TonioElGringo
May 21 at 10:51
add a comment |
Here's a shorter macro version.
First write a single line with the contents
- "1"
Then type the following:
qqyypCtrl-Aq98@q
qq—start recording
yyp—Duplicate the line
Ctrl-A—Increment the number
q—End the recording
98@q—Replay 98 times
add a comment |
Here's a shorter macro version.
First write a single line with the contents
- "1"
Then type the following:
qqyypCtrl-Aq98@q
qq—start recording
yyp—Duplicate the line
Ctrl-A—Increment the number
q—End the recording
98@q—Replay 98 times
add a comment |
Here's a shorter macro version.
First write a single line with the contents
- "1"
Then type the following:
qqyypCtrl-Aq98@q
qq—start recording
yyp—Duplicate the line
Ctrl-A—Increment the number
q—End the recording
98@q—Replay 98 times
Here's a shorter macro version.
First write a single line with the contents
- "1"
Then type the following:
qqyypCtrl-Aq98@q
qq—start recording
yyp—Duplicate the line
Ctrl-A—Increment the number
q—End the recording
98@q—Replay 98 times
edited May 20 at 17:10
answered May 20 at 16:10
RichRich
15.7k12168
15.7k12168
add a comment |
add a comment |
I would do it as follow:
- Somewhere in your file (before where you want your list), add a line with the first number - 1 (most likely 0),
- Make a mark at this place (
ma
) - Make an empty line where you want your list and make another mark there (
mb
)
Your file would, at this point, look like this (The lines 1 and 2 don't matter, they are just here to say where the marks are):
- Record the following macro:
qq // Start the macro in register q
`a // go to mark a
CTRL-a // Increase the number
yiw // Copy the number
`b // Go to mark b
i- " // Go in insert mode, insert - "
<esc>p // leave the insert mode and paste the number
A"<CR><esc> // Closes the quote, add a new line and leave the insert mode
mb // Update the mark b to be here
q // Stop recording the macro
100@q // Run the macro 100 times
You can delete the line where the mark a is, as it was just to store the counter.
And voila.
I like the idea of using a variable. Is there an option to save (and increase) this variable inside a register? That would make the macro much shorter.
– Joel
May 20 at 15:17
1
I am not sure it is easily possible (without using a:
command, which is fine too, but I don't think that would make the macro simpler). Maybe someone will have a suggestion to improve it?
– padawin
May 20 at 15:19
add a comment |
I would do it as follow:
- Somewhere in your file (before where you want your list), add a line with the first number - 1 (most likely 0),
- Make a mark at this place (
ma
) - Make an empty line where you want your list and make another mark there (
mb
)
Your file would, at this point, look like this (The lines 1 and 2 don't matter, they are just here to say where the marks are):
- Record the following macro:
qq // Start the macro in register q
`a // go to mark a
CTRL-a // Increase the number
yiw // Copy the number
`b // Go to mark b
i- " // Go in insert mode, insert - "
<esc>p // leave the insert mode and paste the number
A"<CR><esc> // Closes the quote, add a new line and leave the insert mode
mb // Update the mark b to be here
q // Stop recording the macro
100@q // Run the macro 100 times
You can delete the line where the mark a is, as it was just to store the counter.
And voila.
I like the idea of using a variable. Is there an option to save (and increase) this variable inside a register? That would make the macro much shorter.
– Joel
May 20 at 15:17
1
I am not sure it is easily possible (without using a:
command, which is fine too, but I don't think that would make the macro simpler). Maybe someone will have a suggestion to improve it?
– padawin
May 20 at 15:19
add a comment |
I would do it as follow:
- Somewhere in your file (before where you want your list), add a line with the first number - 1 (most likely 0),
- Make a mark at this place (
ma
) - Make an empty line where you want your list and make another mark there (
mb
)
Your file would, at this point, look like this (The lines 1 and 2 don't matter, they are just here to say where the marks are):
- Record the following macro:
qq // Start the macro in register q
`a // go to mark a
CTRL-a // Increase the number
yiw // Copy the number
`b // Go to mark b
i- " // Go in insert mode, insert - "
<esc>p // leave the insert mode and paste the number
A"<CR><esc> // Closes the quote, add a new line and leave the insert mode
mb // Update the mark b to be here
q // Stop recording the macro
100@q // Run the macro 100 times
You can delete the line where the mark a is, as it was just to store the counter.
And voila.
I would do it as follow:
- Somewhere in your file (before where you want your list), add a line with the first number - 1 (most likely 0),
- Make a mark at this place (
ma
) - Make an empty line where you want your list and make another mark there (
mb
)
Your file would, at this point, look like this (The lines 1 and 2 don't matter, they are just here to say where the marks are):
- Record the following macro:
qq // Start the macro in register q
`a // go to mark a
CTRL-a // Increase the number
yiw // Copy the number
`b // Go to mark b
i- " // Go in insert mode, insert - "
<esc>p // leave the insert mode and paste the number
A"<CR><esc> // Closes the quote, add a new line and leave the insert mode
mb // Update the mark b to be here
q // Stop recording the macro
100@q // Run the macro 100 times
You can delete the line where the mark a is, as it was just to store the counter.
And voila.
edited May 20 at 15:18
answered May 20 at 15:13
padawinpadawin
7687
7687
I like the idea of using a variable. Is there an option to save (and increase) this variable inside a register? That would make the macro much shorter.
– Joel
May 20 at 15:17
1
I am not sure it is easily possible (without using a:
command, which is fine too, but I don't think that would make the macro simpler). Maybe someone will have a suggestion to improve it?
– padawin
May 20 at 15:19
add a comment |
I like the idea of using a variable. Is there an option to save (and increase) this variable inside a register? That would make the macro much shorter.
– Joel
May 20 at 15:17
1
I am not sure it is easily possible (without using a:
command, which is fine too, but I don't think that would make the macro simpler). Maybe someone will have a suggestion to improve it?
– padawin
May 20 at 15:19
I like the idea of using a variable. Is there an option to save (and increase) this variable inside a register? That would make the macro much shorter.
– Joel
May 20 at 15:17
I like the idea of using a variable. Is there an option to save (and increase) this variable inside a register? That would make the macro much shorter.
– Joel
May 20 at 15:17
1
1
I am not sure it is easily possible (without using a
:
command, which is fine too, but I don't think that would make the macro simpler). Maybe someone will have a suggestion to improve it?– padawin
May 20 at 15:19
I am not sure it is easily possible (without using a
:
command, which is fine too, but I don't think that would make the macro simpler). Maybe someone will have a suggestion to improve it?– padawin
May 20 at 15:19
add a comment |