Kakoune: Is there any command to run a script like ! in vim

Created on 14 Sep 2020  路  6Comments  路  Source: mawww/kakoune

I want to be able to write a script to run my unit tests, but there doesn't seem to be a command for this?

The :terminal command seems to open the script in a new terminal, then immediately disappears. This isn't really useful for running unit tests.

Most helpful comment

You could also use something along the lines of :e -scratch; exec <a-!>command<ret>.

In any case, running commands in a loop is really the shell's job, not the editor's. If you can't write code without that feature, consider using a terminal emulator like emacs or neovim. Or just spawn a shell.

All 6 comments

I wrote the following in my configuration:

define-command -params .. -shell-completion -docstring %{
    Forward all arguments to a shell for evaluation
} shell %{
    echo -- %sh{ /bin/sh -c -- "$*" }
}
alias global ! shell

To be used as :! command.

Thanks @lenormf. How is this to be used? For me it runs a script and then doesn't seem to do anything afterwards. How do you see your test output?

Kakoune doesn't have a way to run an external command in the foreground the way Vim does, in part because Kakoune commands are executed on the server and there's no easy way to pipe the output to whatever client you're using.

If your test harness produces test output like a C compiler (filename:line:column:message) you can set the makecmd option to the command that runs the tests, and :make to run the tests and display the output in a new buffer. Even if your tests don't produce output like that, it might still be handy - you just won't be able to jump to the source of an error if Kakoune can't understand the syntax of error messages. If you're feeling adventurous, you might like to make a copy of the make.kak plugin and customise it to recognise the output of the tool you're using.

Thanks @Screwtapello

You could also use something along the lines of :e -scratch; exec <a-!>command<ret>.

In any case, running commands in a loop is really the shell's job, not the editor's. If you can't write code without that feature, consider using a terminal emulator like emacs or neovim. Or just spawn a shell.

Thanks @lenormf. How is this to be used? For me it runs a script and then doesn't seem to do anything afterwards. How do you see your test output?

With a little adjustment you can just write the output into a file (mktemp comes to mind) and do whatever you like with that, to see it (open it in a buffer, echo it, use info). The possibilities are endless!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

basbebe picture basbebe  路  4Comments

notramo picture notramo  路  3Comments

fennewald picture fennewald  路  3Comments

a12l picture a12l  路  3Comments

alexherbo2 picture alexherbo2  路  3Comments