| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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 |
|
#2
| |||
| |||
| Great, solutions! Thanks to all the responses, will come here in the future for advice on my VIM needs :-) |
|
#3
| |||
| |||
| 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 wehaven't mentioned this yet: :r !printf '192.168.0.\%s\n' {1..254} This one needs bash shell. |
|
#4
| |||
| |||
| 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 |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.