Re: Vim: Increment numbers in Vim

This is a discussion on Re: Vim: Increment numbers in Vim within the Editors forums in Theory and Concepts category; Teemu Likonen scripsit: > J O'Connell wrote: > >> Teemu Likonen wrote: >>> With Vim's script language one can do >>> :for i in range(254) | execute 'normal o192.168.0.'.(i+1) | endfor >>> for example. > >> How may we nominate this as an example of brevity, simplicity, and >> elegance? > > Hmm, let's make it even more elegant and simple: > > :for i in range(1,254) | execute 'normal o192.168.0.'.i | endfor :for i in range(1,254) | put ='192.168.0.'.i | endfor m. -- LaTeX + Vim = http://vim-latex.sourceforge.net/ Vim Universal Templates: http://vim.sf.net/script.php?script_id=1078 vim.pl - http://skawina.eu.org/mikolaj CLEWN - http://clewn.sf.net...

Go Back   Application Development Forum > Theory and Concepts > Editors

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-04-2008, 05:53 PM
Mikolaj Machowski
Guest
 
Default Re: Vim: Increment numbers in Vim

Teemu Likonen scripsit:
> J O'Connell wrote:
>
>> Teemu Likonen wrote:
>>> With Vim's script language one can do
>>> :for i in range(254) | execute 'normal o192.168.0.'.(i+1) | endfor
>>> for example.

>
>> How may we nominate this as an example of brevity, simplicity, and
>> elegance?

>
> Hmm, let's make it even more elegant and simple:
>
> :for i in range(1,254) | execute 'normal o192.168.0.'.i | endfor


:for i in range(1,254) | put ='192.168.0.'.i | endfor



m.
--
LaTeX + Vim = http://vim-latex.sourceforge.net/
Vim Universal Templates: http://vim.sf.net/script.php?script_id=1078
vim.pl - http://skawina.eu.org/mikolaj
CLEWN - http://clewn.sf.net
Reply With Quote
  #2  
Old 08-04-2008, 06:36 PM
Andrew Woods
Guest
 
Default Re: Vim: Increment numbers in Vim

Great, solutions! Thanks to all the responses, will come here in the
future for advice on my VIM needs :-)
Reply With Quote
  #3  
Old 08-05-2008, 02:03 AM
Teemu Likonen
Guest
 
Default Re: Vim: Increment numbers in Vim

Mikolaj Machowski wrote:

> Teemu Likonen scripsit:


>> :for i in range(1,254) | execute 'normal o192.168.0.'.i | endfor

>
> :for i in range(1,254) | put ='192.168.0.'.i | endfor


Nice. It's fun to try to come up with different solutions. I guess we
haven't mentioned this yet:

:r !printf '192.168.0.\%s\n' {1..254}

This one needs bash shell.
Reply With Quote
  #4  
Old 08-05-2008, 06:06 AM
Stephane Chazelas
Guest
 
Default Re: Vim: Increment numbers in Vim

2008-08-05, 06:03(+00), Teemu Likonen:
> Mikolaj Machowski wrote:
>
>> Teemu Likonen scripsit:

>
>>> :for i in range(1,254) | execute 'normal o192.168.0.'.i | endfor

>>
>> :for i in range(1,254) | put ='192.168.0.'.i | endfor

>
> Nice. It's fun to try to come up with different solutions. I guess we
> haven't mentioned this yet:
>
> :r !printf '192.168.0.\%s\n' {1..254}
>
> This one needs bash shell.


{1..254} is a feature that bash copied from ksh93 which it
itself copied from zsh. And in zsh, you can use print -l to
avoid having to use printf as I said in an earlier message:

:r! print -l 192.168.0.{1..254}

Personally, I find using ! neater that using vim's extension
language as it appeals to my taste for orthogonality

With zsh, you can also do:

:r! repeat 254 echo 192.168.0.$((++i))

POSIXly, you can also do:

:r! awk 'BEGIN{while (++i<=254) print "192.168.0." i}'


--
Stéphane
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 04:22 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.