Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm implementing hundreds of similar functions at the moment which take on the form

String name(String arg1, String arg2, String arg3, String arg4) {
              name, arg1, arg2, arg3, arg4);

The tricky part is the function can take between 2 and 10 arguments.

If I could have a way to make vim ask me for "Name of function: ", "Number of args: ", "arg1: " I could easily build these functions.

If you need further information to help you help me, I would be more than willing to supply.


share|improve this question
up vote 1 down vote accepted

not really an answer: if you are already at a point when you recognize that you should automate this (for hundreds of functions), you should go one step further and automate it completely: write a code generator in insert_your_favourite_language_here.

share|improve this answer
I'm actually thinking about doing this right now but I would love to become more proficient with vim. – flumpb Oct 17 '11 at 14:36
good intention but for this task maybe the wrong time :) – akira Oct 17 '11 at 14:37
Good point, I went ahead and wrote the generator (in..... c++!) and finished all the methods :). I'll have to go learn vim scripting in some free time at another date – flumpb Oct 17 '11 at 16:36

First idea: in vim has for (Try :help for).

You can create a simple function to do this.

share|improve this answer

Here is an answer based on mu-template (it should be easy to port it to plain viml using :put).

VimL: " {rtp}/template/{your_filetype}/{yourgenerator}.template
VimL: let s:nb_args = INPUT("Number of args: ")
VimL: let s:args=map(copy(range(1,s:nb_args)), '"arg".v:val')
VimL: let s:formal = join(map(copy(s:args), "'String '.v:val"), ', ')
VimL: let s:real = join(s:args, ', ')
VimL: let s:format = join(map(copy(s:args), "v:val.'={'.v:val.'}'"), '&')
String name(<+s:formal+>) {
        name, <+s:real+>);
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .