3

I have this mvn command

mvn install:install-file -DgroupId=i.hate.james.blunt -DartifactId=yourartifactid... -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/jarfile

And I want to transfer it to a command in vim, at the moment I have this

command -nargs=* MvnAddToRepositoy :!mvn install:install-file -DgroupId=i.hate.james.blunt -DartifactId=<arg1> -Dversion=1.0 -Dpackaging=jar -Dfile=<arg2>

I am unable to find this in vim docs or an example on the net.

Can anyone help?

Edit

The error message above was saying the command it was trying

mvn install:install-file -DgroupId=mx.com.root -DartifactId=<arg1> -Dversion=1.0 -Dpackaging=jar -Dfile=<arg2>'
2
  • command -nargs=* Ls :!ls -ltr <args> seems to work fine here. Are you getting any errors? Commented Apr 12, 2011 at 22:56
  • So I reference them both with <args> and it decides which to use from the input order Commented Apr 12, 2011 at 23:08

2 Answers 2

13

My understanding is that Vim doesn't make multiple args accessible with the <arg1>, <arg2> placeholders like you think it does. Are you getting that from docs somewhere?

You might want to take a look at help for <f-args>. This lets you define your own function that you can pass the arguments to, and process things within your function to call the shell command the way you want.

This is from the Vim help:

" Call a user function (example of <f-args>)
:com -nargs=* Mycmd call Myfunc(<f-args>)

When executed as: 
    :Mycmd arg1 arg2
This will invoke: 
    :call Myfunc("arg1","arg2")

I assume you could then write things within Myfunc to do what you want. For example the (untested) code below.

function Myfunc(myarg1, myarg2)
     execute '!mvn install:install-file -DgroupId=i.hate.james.blunt -DartifactId=' . 
        \   a:myarg1 . ' -Dversion=1.0 -Dpackaging=jar -Dfile=' . a:myarg2
endfunction
Sign up to request clarification or add additional context in comments.

2 Comments

I read the same vim help and tried to improvise a little. Anyway thats exactly what I was looking for
Is there a way to split the arguments using quotes instead of spaces? For example, Mycmd "arg 1" "arg 2" instead of Mycmd arg\ 1 arg\ 2. I can't seem to find it in the docs.
0

Using answer of Herbert the function looks like this:

" Adds dependencies to local m2 repo
fun! FunMvnAddToRepository(artifactid, pathtojar)
    execute '!mvn install:install-file -DgroupId=mx.com.root -DartifactId=' . 
   \   a:artifactid . ' -Dversion=1.0 -Dpackaging=jar -Dfile=' . a:pathtojar
endfunction

And command looks like this:

" Adds dependencies to local m2 repo
command -nargs=* MvnAddToRepositoy call FunMvnAddToRepository(<f-args>)

And it works

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.