a small plugin for :call system() in vim

29 views
Skip to first unread message

Marcin Szamotulski

unread,
Sep 21, 2012, 1:21:23 PM9/21/12
to Vim Use
Hello,

I just have found a neat way for doing:

:echo system('command')

I attach a small plugin which does the above if the command line starts
with ':! '. If you know of any existing such plugin let me know, if not
I'll be happy to publish it on vim.org. Here are doc notes from the
plugin:

" This is a tiny vim script which might have been discvered ages ago (but I am
" unaware). Its rather for vim than gvim users.
"
" When executing commands from vim you enter a vim shell where you see the
" output. In many situations this is not what you want and you'd prefere
" :call system("command")
" but it is a lot to type, and you don't have completion. With this snipet
" every command which start with:
" :! command
" a space after the "!" will be wrapped into system() and the output will be
" echoed.
" The executed command will also be echoed (on the very top).
"
" Benefits: you get completion for system commanads and system files.
" Drawbacks: I'll be happy to know any of them :)
"
" The idea how to do that was borrowed from emacscommandline plugin.


Any suggestions for the plugin name will be welcome.

Best regards,
Marcin
system.vim

Marc Weber

unread,
Sep 21, 2012, 1:33:34 PM9/21/12
to vim_use
Excerpts from Marcin Szamotulski's message of Fri Sep 21 19:21:23 +0200 2012:
> Hello,
>
> I just have found a neat way for doing:
> :echo system('command')

why is echo system('command') better than :! ?

Using :! you can stop it using ctrl-c again.
The only advantage I could see is that % is not treated specially.
Ah, its about completion ?

Marc Weber

Marcin Szamotulski

unread,
Sep 21, 2012, 1:38:54 PM9/21/12
to vim...@googlegroups.com
Yes it is! and how less you need to type, and how nice it looks ;)
Hmm, you are right % is not treated specially, but I think it is
a disadvantage, though.

Marcin Szamotulski

>
> Marc Weber
>
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php

Marcin Szamotulski

unread,
Sep 21, 2012, 3:58:44 PM9/21/12
to vim...@googlegroups.com
Dear Vimers,

I have a simple question. Since I want to mentain a nice history for the
plugin proposed below. The idea is to add history entry for the command
that was given by the user, then the plugin changes it to :call system()
and this is also remembered in the history. I'd like to remove this
entry from the history but ShellFilterPost autocommand is not fired in
this case (since we do not run a command throgh :!). So the question is
how to delete the last history item (via autocommand). I thought that it
would be nice to disable history and then reset it back, but there is
the same problem: how to reset it back (and as far as I can see, setting
'history' to 0 will cut the history).

Best regards,
Marcin Szamotulski

Gary Johnson

unread,
Sep 21, 2012, 4:54:37 PM9/21/12
to vim...@googlegroups.com
On 2012-09-21, Marcin Szamotulski wrote:
> On 19:33 Fri 21 Sep , Marc Weber wrote:
> > Excerpts from Marcin Szamotulski's message of Fri Sep 21 19:21:23 +0200 2012:
> > > Hello,
> > >
> > > I just have found a neat way for doing:
> > > :echo system('command')
> >
> > why is echo system('command') better than :! ?
> >
> > Using :! you can stop it using ctrl-c again.
> > The only advantage I could see is that % is not treated specially.
> > Ah, its about completion ?
> Yes it is! and how less you need to type, and how nice it looks ;)

This must be for shells that don't have command completion? From
both vim and gvim on my Linux system, command completion from :!
works fine.

Regards,
Gary

Marcin Szamotulski

unread,
Sep 21, 2012, 6:13:19 PM9/21/12
to vim...@googlegroups.com
The problem is that there is no completion on the vim command line when
you type:
:echo system("....

Regards,
Marcin

Gary Johnson

unread,
Sep 21, 2012, 6:26:14 PM9/21/12
to vim...@googlegroups.com, Marcin Szamotulski
I don't understand why anyone would want to use ":echo system('..."
instead of ":!...".

Regards,
Gary

Reply all
Reply to author
Forward
0 new messages