| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi, I was wondering if it is possible to increment with VIM. For example I'm trying to ping an IP range that needs to be contained in a file. So I would like to create say 254 lines such as: 192.168.0.1 192.168.0.2 .... 192.168.0.254 ,without having the manually increment them yourself? |
|
#2
| |||
| |||
| 2008-08-4, 08:07(-07), Andrew Woods: > I was wondering if it is possible to increment with VIM. For example > I'm trying to ping an IP range that needs to be contained in a file. > So I would like to create say 254 lines such as: > > 192.168.0.1 > 192.168.0.2 > ... > 192.168.0.254 > > ,without having the manually increment them yourself? You can use <Ctrl-A> in command mode. So if you have a line with 192.168.0.1 You can record a macro ("a") like: qayyp$<Ctrl-A>q And then: 252@a to call the macro 252 times. On GNU systems, you can also do: :r! seq -f 192.168.1.\%g 254 Or if your shell is zsh: :r! print -l 192.168.1.{1..254} You can probably do some loops in vim language, but I don't do that often enough for me to remember the syntax, so I'd need to lookup the manual. -- Stéphane |
|
#3
| |||
| |||
| On Aug 4, 5:21*pm, Stephane CHAZELAS <stephane_chaze...@yahoo.fr> wrote: > 2008-08-4, 08:07(-07), Andrew Woods: > > > I was wondering if it is possible to increment with VIM. For example > > I'm trying to ping an IP range that needs to be contained in a file. > > So I would like to create say 254 lines such as: > > > 192.168.0.1 > > 192.168.0.2 > > ... > > 192.168.0.254 > > > ,without having the manually increment them yourself? > > You can use <Ctrl-A> in command mode. > > So if you have a line with > > 192.168.0.1 > > You can record a macro ("a") like: > > qayyp$<Ctrl-A>q > > And then: > > 252@a > > to call the macro 252 times. > > On GNU systems, you can also do: > > :r! seq -f 192.168.1.\%g 254 > > Or if your shell is zsh: > > :r! print -l 192.168.1.{1..254} > > You can probably do some loops in vim language, but I don't do > that often enough for me to remember the syntax, so I'd need to > lookup the manual. > > -- > Stéphane Hi Stéphane, Great thanks, your macro idea was very useful, I must start trying to use them more often. Drew |
|
#4
| |||
| |||
| Stephane CHAZELAS wrote: > 2008-08-4, 08:07(-07), Andrew Woods: >> I was wondering if it is possible to increment with VIM. For example >> I'm trying to ping an IP range that needs to be contained in a file. >> So I would like to create say 254 lines such as: >> >> 192.168.0.1 >> 192.168.0.2 >> ... >> 192.168.0.254 > You can probably do some loops in vim language, but I don't do > that often enough for me to remember the syntax, so I'd need to > lookup the manual. With Vim's script language one can do :for i in range(254) | execute 'normal o192.168.0.'.(i+1) | endfor for example. |
|
#5
| |||
| |||
| hi , it's a little a bit dirty but it works : you need two marvellous features of Vim. - you can record sequences of instructions with the 'q' command (for exemple 'qa' will record the following sequence in the register 'a', type 'q' again to close the sequence) - C-a increment numbers ! so you type your first number i 125.200.666.0 then you register the following sequence qa yy p $ C-a q Hit @a to execute your sequence and @@ to reexecute the last sequence. 50@a will do it 50 times. I'm sure there is a clean way to put it into your vimrc or something but I'm too lasy for searching . |
|
#6
| |||
| |||
| I guess i've been too slow ^^. I find Teemu's solution much better than mine. |
|
#7
| |||
| |||
| 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. To The List: How may we nominate this as an example of brevity, simplicity, and elegance? could it be placed in the official Vim FAQ or one of the Vim 'Tips-n-Tricks' sites? -Fionn |
|
#8
| |||
| |||
| 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 |
|
#9
| |||
| |||
| Andrew Woods wrote: > Hi, > > I was wondering if it is possible to increment with VIM. For example > I'm trying to ping an IP range that needs to be contained in a file. > So I would like to create say 254 lines such as: > > 192.168.0.1 > 192.168.0.2 > ... > 192.168.0.254 > > ,without having the manually increment them yourself? The visincr plugin makes this pretty simple: 192.168.0.1 ma"ay'a (get a copy of the line into register a) 253"ap (make 254 total copies) Now, use visual-mode (go to the rightmost 1, ctrl-v, G). Using visincr: I That'll make the visually-selected region an incremented list. You can get visincr from: http://mysite.verizon.net/astronaut/...x.html#VISINCR (cutting edge) http://vim.sourceforge.net/scripts/s...?script_id=670 (stable) Visincr also supports hexadecimal, octal, roman, day, and various date incrementing. Regards, Chip Campbell |
|
#10
| |||
| |||
| J O'Connell wrote: > To The List: > > How may we nominate this as an example of brevity, simplicity, and > elegance? > > could it be placed in the official Vim FAQ or one of the Vim > 'Tips-n-Tricks' sites? Anybody may add tips to the Vim tips wiki: http://vim.wikia.com/wiki/Main_Page - Chris |
![]() |
| 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.