ShellCmdPre autocommand ?

33 views
Skip to first unread message

Marc Chantreux

unread,
Sep 6, 2026, 6:33:53 AMSep 6
to vim...@googlegroups.com
hello vimmers,

A. The problem

* the use of expansions like <cfile> is very powerful but typing
those are boring and error prone ( < cfile> is a shell redir)
* sometimes it can be really usefull to have the content of <cfile>
as an exported variable.
* environment variables have autocompletion, vim expansions doesn't

:r!dpkg -r <cfile>

B. The solutions

There are many but I came to the idea that the most reusable feature
would be the ShellCmdPre autocommand (ShellCmdPost already exists).

I have no time to dive into vim developpement but if needed, I'll be
happy to sponsor it (I think Christian Brabandt asked for financial help
so he can spend more time on vim)

thanks for any feedbacks.


C. The context

In few months, I'll give a new version of the talk "acme changed my life"
https://github.com/eiro/talk-acme-changed-my-life in which I explain
that "!" by far the most underated feature of vi and all its clone and
the basics of it.

In this new version, I'll instist on another underated features: vim
expansions with expressions like

:e <cfile>/README
:r!dpkg -r <cfile>

and the way it can interact with features outside of vim. as exemple:
if you have suffix aliases set up in your ~/.zlogin, you can just type

:!<cfile>

to open a file. you can possibly map it to something like <space>x as
it's really generic.

but there the problem I mentionned before and what I really would like
is to introduce something like

au ShellCmdPre {
$f = expand('<cfile>')
$F = expand('<cFILE>')
$w = expand('<cword>')
$W = expand('<cWORD>')
}

so now I just need to type

:!$f

--
Marc Chantreux

Maxim Kim

unread,
Sep 7, 2026, 8:30:57 PMSep 7
to vim_use
What about 

:!<CTRL-R><CTRL-f>

?

Marc Chantreux

unread,
Sep 8, 2026, 1:17:39 AMSep 8
to vim...@googlegroups.com
hello,

On Mon, Sep 07, 2026 at 05:30:56PM -0700, Maxim Kim wrote:
> What about 
> :!<CTRL-R><CTRL-f> ?

worth to mention but something like

:r!dpkg -r <cfile>

is reusable from history so you can type it once and use it repeatedly
and <cfile> updated.

not only

:r!dpkg -r $c

is faster to type and less error prone but as it is a environment
variable, I can use it it a custom script. I can also imagine exporting
more informations like getline(), line(), col() ...

anyway: I never use <c-r><c-f> but it's worth to mention the <c-r>* during
the talk. Thank you!

--
Marc Chantreux
☎ 03.68.85.60.79
Reply all
Reply to author
Forward
0 new messages