Method 1 :
:put =range(11,15)
This will create a series of increasing numbers after the current line including 11 and 15.
output will be-
11 12 13 14 15
Method 2 :
Some times if you want to add a constant predefined string before the number series, then you you can go using loop to create a list.
for i in range(1,6) | put ='10.168.0.'.i | endfor
Executing the command will insert the following lines after the current line
10.168.0.1 10.168.0.2 10.168.0.3 10.168.0.4 10.168.0.5 10.168.0.6
Method 3 :
Another simple way is to use Ctrl+A in a macro.
for example, some times you may need to initialize a array of size 100.
array[0] = 0
array[1] = 0
array[2] = 0
... so on
type array[0] = 0; then start recording macro.
Type the following commands without pressing enter.
qa [ record to buffer 'a' ] Y [ copy the current line ] p [ paste the line ] Ctrl-A [ Ctrl+A increment the number or use Ctrl+X to decrement] q [ stop recording macro ]
now type 100@a to perform the macro 100 times.
array[0] = 0; array[1] = 0; array[2] = 0; array[3] = 0; array[4] = 0; ... and so on
if you want to increase the index and assigned value also then type Ctrl+A by moving the courser to the value.
0 comments:
Post a Comment