# Aliases for common cargo commands

**URL:** <https://discuss.kakoune.com/t/aliases-for-common-cargo-commands/701>\
**Category:** Help\
**Tags:** plugins\
**Created:** [September 5, 2019, 10:03pm UTC](https://discuss.kakoune.com/t/aliases-for-common-cargo-commands/701 "2019-09-05T22:03:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmusser](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/c/85e7bf/32.png) [@cmusser](https://discuss.kakoune.com/u/cmusser)\
**Post date:** [September 5, 2019, 10:03pm UTC](https://discuss.kakoune.com/t/aliases-for-common-cargo-commands/701/1 "2019-09-05T22:03:27Z")

</div>

I’m using the cargo module that provides access to Cargo commands with nice in-editor output. I wanted to shorten some commonly used commands, so `:cargo test` could just be `:ct`, `:cargo build` could be `:cb`, etc.

I can’t figure out how to do a more complex one where the arguments to my “shortcut” would be passed on to the thing that actually executes cargo. an example would be doing a Cargo run that could be invoked like `:cr --release -- --argument value --other-arg other-value`. I tried the following in my .kakrc:

```auto
def cr -file-completion -params .. -command-completion -docstring "cargo run <params>" %{
    write-all -sync
    cargo run "$@"
}

```

The `"$@"` clearly isn’t right, but the intent is: "take all the arguments to this command and pass them to `cargo run`". How can this be accomplished?

---

<div class="post-metadata">

**Author:** ![andreyorst](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/andreyorst/32/29_2.png) [@andreyorst](https://discuss.kakoune.com/u/andreyorst)\
**Post date:** [September 6, 2019, 3:37am UTC](https://discuss.kakoune.com/t/aliases-for-common-cargo-commands/701/2 "2019-09-06T03:37:20Z")

</div>

`%arg{@}`?

---

<div class="post-metadata">

**Author:** ![Screwtapello](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/screwtapello/32/12_2.png) [@Screwtapello](https://discuss.kakoune.com/u/Screwtapello)\
**Post date:** [September 6, 2019, 6:11am UTC](https://discuss.kakoune.com/t/aliases-for-common-cargo-commands/701/3 "2019-09-06T06:11:06Z")

</div>

This might not have been documented when you started using the Cargo plugin, but it provides a “cargo” user-mode for quick access to the most common commands. Following [step 4 of the installation instructions](https://gitlab.com/Screwtapello/kakoune-cargo#installation), instead of `:ct<ret>` to run my tests, I can type `,ct` to do the same thing, and save a keystroke!

Of course, that doesn’t let me add extra command-line arguments like the `:cargo` command does. Generally, if there’s a variation I run a lot, i just add it to the “cargo” user mode myself. For example, I have the following mapping to build tests for Windows and run them in Wine:

```
map -docstring "test Windows" global cargo w %{: cargo test --no-fail-fast --target x86_64-pc-windows-gnu<ret>}
```

---

<div class="post-metadata">

**Author:** ![cmusser](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/c/85e7bf/32.png) [@cmusser](https://discuss.kakoune.com/u/cmusser)\
**Post date:** [September 7, 2019, 3:24pm UTC](https://discuss.kakoune.com/t/aliases-for-common-cargo-commands/701/4 "2019-09-07T15:24:33Z")

</div>

OK, cool.

`%arg{@}` does work for this particular case (adding a new “wrapper” command. But also, I’ve never tried user modesb or the key mapping feature. Those look helpful as well for other situations.

---

<div class="post-metadata">

**Author:** ![cmusser](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/c/85e7bf/32.png) [@cmusser](https://discuss.kakoune.com/u/cmusser)\
**Post date:** [September 7, 2019, 4:18pm UTC](https://discuss.kakoune.com/t/aliases-for-common-cargo-commands/701/5 "2019-09-07T16:18:06Z")

</div>

Actually, yeah, the key mapping is really useful. I converted most of my little “commands” into those and now they’re easier to access via the comma prefix. Nice.
