LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Running a function mutiple times in vim (https://www.linuxquestions.org/questions/linux-general-1/running-a-function-mutiple-times-in-vim-490697/)

fudam 10-08-2006 09:11 PM

Running a function mutiple times in vim
 
Hey,

I've written a function in vim and it works great. I execute it as follows:
Code:

:call Myfunc()
My question is, what if I want to run Myfunc() 7 times in a row? Or 11, or whatever. Does anyone know how to do this? typing in :5 Myfunc() did not work (instead it takes you to line 5 and executes Myfunc).

TIA for any help, this is starting to hurt my head...

-fudamn

bigrigdriver 10-09-2006 12:04 AM

Check out the vimbook, page 356. It has an example of how to use a while loop in command mode to repeat some action multiple times. I suppose calling a function that way would work.

muha 10-09-2006 02:31 AM

Look at this dot ~> .
Seriously :D In vi (i don't know about vim) you can run a command, like p(aste) and use the . (dot) to run the previous command again.
Usually in vi the syntax format is like: :<number of times><command>
So to repeat a paste three times do:
yy first yank a line
p paste it once
. repeat the paste
3. repeat the paste three times
So I think you can use:
:call Myfunc()
:3.
Let me know if it works, ok?

fudam 10-09-2006 08:34 PM

Thanks for reply fellas,

muha: Sorry the dot doesn't work on function calls. Good try though. :D

bigrigdriver: Are you referring to the manual? Or the vim PDF book on their website? It's a bit late and I'm off to bed, but I'll check out your reference tomorrow. Thanks!

-fudamn

muha 10-10-2006 02:30 PM

that's a shame indeed :P


All times are GMT -5. The time now is 09:41 PM.