Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write lines in Vim using a for loop

Tags:

text

vim

How to make Vim write lines into a file according to a very simple arithmetic pattern?

Example:

foo1
foo2
foo3
...
foo99
foo100

I came up with the following solution using Ex commands

:for i in range(1,100)
:  execute "normal ofoo" . i
:endfor

but I am convinced there must be something more straightforward.

like image 266
Siméon Avatar asked Mar 31 '15 10:03

Siméon


People also ask

How to modify multiple lines in vim?

Edit multiple linesUse Ctrl+V to enter visual block mode Move down with jj to select the columns of text in the lines you want to comment. Then hit Shift+I and type the text you want to insert. Then press Escape, the inserted text will appear on all lines.

How do you call a function in Vim?

Calling A Function Vim has a :call command to call a function. The call command does not output the return value. Let's call it with echo . To clear any confusion, you have just used two different call commands: the :call command-line command and the call() function.


1 Answers

I would do it with macro.

First type one line:

foo1

then

qqYp<c-a>q

finally replay the macro:

98@q
like image 164
Kent Avatar answered Sep 28 '22 14:09

Kent