2

I am trying to create a user defined command in vim as a replacement for a quickfixlist command

I defined the command like this:

:command G -nargs=1 cr <args>

Now, when I type :G 1, I expected vim to execute :cr 1 and go to error number 1 from quickfix list. Instead I get a "trailing characters" error. Any idea what might be causing this?

Thank you

1 Answer 1

4

Your definition creates G as an alias for :-nargs=1 cr <args>, taking no arguments. That's why :G 1 gives you E488: Trailing characters.

Running just :G results in E492: Not an editor command: -nargs=1 cr.

The fix is to move the command attributes before the command name:

:command -nargs=1 G cr <args>

This way -nargs=1 is interpreted as an attribute, not part of the command replacement.

Sign up to request clarification or add additional context in comments.

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.