How would you repeatedly produce these lines?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How would you repeatedly produce these lines?

etoipm1i0
I'm coding in Python and need to produce a number of lines like the following

> p3[0] = {'name': , 'symbol': , 'number': }
> p3[1] = {'name': , 'symbol': , 'number': }
> ...

and I'm wondering the best way to go about this.  My main thought is to just copy-paste and maybe fill the brackets with some kind of place-keeper and then try to figure out a way to sequentially replace them with increasing integers.  But somehow it seems like there out to be a more elegant Vim solution.

Any thoughts?

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How would you repeatedly produce these lines?

Markus Osterhoff
* [hidden email] <[hidden email]> [160201 06:18]:
> I'm coding in Python and need to produce a number of lines like the following
> > p3[0] = {'name': , 'symbol': , 'number': }
For that I usually use keyboard macros: copy the line, jump to the
bracket, increase. The keys are
        Ypf[CTRL-A
and as a macro e.g.
qqYpf[CTRL-Aq
100@q to repeat 100 times

Greetings,
mo

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How would you repeatedly produce these lines?

A. S. Budden
In reply to this post by etoipm1i0
On 1 February 2016 at 05:18,  <[hidden email]> wrote:
> I'm coding in Python and need to produce a number of lines like the following
>
>> p3[0] = {'name': , 'symbol': , 'number': }
>> p3[1] = {'name': , 'symbol': , 'number': }
>> ...
>
> and I'm wondering the best way to go about this.  My main thought is to just copy-paste and maybe fill the brackets with some kind of place-keeper and then try to figure out a way to sequentially replace them with increasing integers.  But somehow it seems like there out to be a more elegant Vim solution.

There are probably lots of different approaches, but I'd probably do
something like this:

Copy the first line, then paste it n (in this case 7) times:

    yy7p

Move the cursor over the 0 in the first line, go into visual blockwise
mode and select the whole column:

    Ctrl-V 7j

Increment using Dr Chip's visincr plugin
(http://vim.sourceforge.net/scripts/script.php?script_id=670)

    :I

Alternatively (if you don't want to use plugins), after copying and
pasting, you could do:

    :let a = 0 | g@^p3@s/0/\=a/ | let a += 1

This creates a variable 'a' and initialises it to zero.  Then, for
every line starting in p3 (g@^p3@) it substitutes the first 0 with the
current value of a and then increments a.

Al

--
http://www.cgtk.co.uk

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How would you repeatedly produce these lines?

Charles Campbell
In reply to this post by etoipm1i0
[hidden email] wrote:
> I'm coding in Python and need to produce a number of lines like the following
>
>> p3[0] = {'name': , 'symbol': , 'number': }
>> p3[1] = {'name': , 'symbol': , 'number': }
>> ...
> and I'm wondering the best way to go about this.  My main thought is to just copy-paste and maybe fill the brackets with some kind of place-keeper and then try to figure out a way to sequentially replace them with increasing integers.  But somehow it seems like there out to be a more elegant Vim solution.
>
> Any thoughts?
>
I'd write the first line:
  p3[0] = ...

Yank it (Y) and put it (say I wanted twenty copies:  19p
Then I'd use ctrl-v and highlight all the 0s.
Then I'd use  :I

The latter command is supported by visincr
(http://www.drchip.org/astronaut/vim/index.html#VISINCR).  It can do
incrementing/decrementing things with binary, octal, hexadecimal, roman
numerals, daynames, monthnames, and dates (ymd, dmy, mdy).

Regards,
Chip Campbell

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How would you repeatedly produce these lines?

Benjamin Fritz
On Monday, February 1, 2016 at 9:00:25 AM UTC-6, Charles Campbell wrote:

> [hidden email] wrote:
> > I'm coding in Python and need to produce a number of lines like the following
> >
> >> p3[0] = {'name': , 'symbol': , 'number': }
> >> p3[1] = {'name': , 'symbol': , 'number': }
> >> ...
> > and I'm wondering the best way to go about this.  My main thought is to just copy-paste and maybe fill the brackets with some kind of place-keeper and then try to figure out a way to sequentially replace them with increasing integers.  But somehow it seems like there out to be a more elegant Vim solution.
> >
> > Any thoughts?
> >
> I'd write the first line:
>   p3[0] = ...
>
> Yank it (Y) and put it (say I wanted twenty copies:  19p
> Then I'd use ctrl-v and highlight all the 0s.
> Then I'd use  :I
>
> The latter command is supported by visincr
> (http://www.drchip.org/astronaut/vim/index.html#VISINCR).  It can do
> incrementing/decrementing things with binary, octal, hexadecimal, roman
> numerals, daynames, monthnames, and dates (ymd, dmy, mdy).
>
> Regards,
> Chip Campbell
Sometime this year (I think patches 754-823) the g_CTRL-A command was introduced to create increasing sequences of integers (:help v_g_CTRL-A). Also CTRL-A/CTRL-X was modified to respect visual mode better. So the plugin is probably not even required anymore.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How would you repeatedly produce these lines?

Ethan Hereth

On Mon, Feb 1, 2016 at 11:24 AM, Ben Fritz <[hidden email]> wrote:
On Monday, February 1, 2016 at 9:00:25 AM UTC-6, Charles Campbell wrote:
> [hidden email] wrote:
> > I'm coding in Python and need to produce a number of lines like the following
> >
> >> p3[0] = {'name': , 'symbol': , 'number': }
> >> p3[1] = {'name': , 'symbol': , 'number': }
> >> ...
> > and I'm wondering the best way to go about this.  My main thought is to just copy-paste and maybe fill the brackets with some kind of place-keeper and then try to figure out a way to sequentially replace them with increasing integers.  But somehow it seems like there out to be a more elegant Vim solution.
> >
> > Any thoughts?
> >
> I'd write the first line:
>   p3[0] = ...
>
> Yank it (Y) and put it (say I wanted twenty copies:  19p
> Then I'd use ctrl-v and highlight all the 0s.
> Then I'd use  :I
>
> The latter command is supported by visincr
> (http://www.drchip.org/astronaut/vim/index.html#VISINCR).  It can do
> incrementing/decrementing things with binary, octal, hexadecimal, roman
> numerals, daynames, monthnames, and dates (ymd, dmy, mdy).
>
> Regards,
> Chip Campbell

Sometime this year (I think patches 754-823) the g_CTRL-A command was introduced to create increasing sequences of integers (:help v_g_CTRL-A). Also CTRL-A/CTRL-X was modified to respect visual mode better. So the plugin is probably not even required anymore.


I don't think I'd quite say that. This plugin is capable of much more than just this specific example. Thank you, by the way, I knew that CTRL-A/X had been modified to work in visual mode, but I was not aware of the g_CTRL_A/X variant! That is super useful!

Cheers!

Ethan Alan
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How would you repeatedly produce these lines?

John Little-4
A plug for Al's second solution, IMO an idiom worth learning because it's so flexible. Any start value, any increment or decrement (or more general, f. ex. geometric, say increase by 10%, or maybe random), and no need for the items to be contiguous, just to match a regex.

Regards, John Little

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.