[mszamot@gmail.com: Re: a small plugin for :call system() in vim]

25 views
Skip to first unread message

Marcin Szamotulski

unread,
Sep 21, 2012, 7:25:25 PM9/21/12
to Vim Use
On 15:26 Fri 21 Sep , Gary Johnson wrote:
> On 2012-09-21, Marcin Szamotulski wrote:
> > On 13:54 Fri 21 Sep , Gary Johnson wrote:
> > > 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
> >
> > The problem is that there is no completion on the vim command line when
> > you type:
> > :echo system("....
>
> I don't understand why anyone would want to use ":echo system('..."
> instead of ":!...".
>
> Regards,
> Gary

In terminal vim "!..." jumps back and forth to the terminal. I prefer to
stay inside vim. One of the reasons is quite trivial: I use different
background color in vim (a dark one) and terminal (rather light). And
there is a small delay time when eyes adjust to another contrast.

Best,
Marcin

Marc Weber

unread,
Sep 21, 2012, 7:45:40 PM9/21/12
to vim_use
Excerpts from Marcin Szamotulski's message of Sat Sep 22 01:25:25 +0200 2012:
> In terminal vim "!..." jumps back and forth to the terminal. I prefer to
> stay inside vim. One of the reasons is quite trivial: I use different
> background color in vim (a dark one) and terminal (rather light). And
> there is a small delay time when eyes adjust to another contrast.
Well - at least you should update your documentation and tell people why
you're using such a workaround.

I'm not sure whether your code is worth a plugin. Eventually a tip on
the wiki is equally fine.

An alternative could be setting an env var in Vim and making your shell
set a background color in the terminal when run from within vim (env var
is set)

If you wan to add history and the like - then you may want to have a
look at additional plugins such as
[Conque Shell plugin](http://code.google.com/p/conque)
[vimproc plugin](http://github.com/Shougo/vimproc/tree/master/doc/)

Then you may have bash history and the like - but no more vi keys.

vim-addon-async is yet another simple buffer view of shell commands
also implementing a minimal history.
github.com/MarcWeber/vim-addon-views is a way to view shell command
outputs in vim buffers supporting refreshing by :e! and the like.

Marc Weber

Gary Johnson

unread,
Sep 21, 2012, 9:59:15 PM9/21/12
to Vim Use
OK, I see now. I usually have the alternate screen disabled (t_ti
and t_te both empty) so I don't see that problem. With those set,
the switching back and forth when using ":!" _is_ kind of annoying.

I also found that ":echo system('..." works well on Windows: it
avoids the new Command Prompt window when using gvim and avoids the
disappearing output when using vim.

In all cases, using ":echo system('..." allows you to use Vim's
built-in pager to scroll back and forth through long outputs without
having to pipe into less.

Now that I understand, that _is_ a useful trick.

Regards,
Gary

Tony Mechelynck

unread,
Sep 21, 2012, 10:02:49 PM9/21/12
to vim...@googlegroups.com
To each his taste. I use different colours in the konsole terminal
(black on pale yellow) and in Vim (as close as I can as in gvim, i.e.
black on white for Normal text and, of course, various colours for
syntax highlights) but I don't prefer to stay inside Vim. Typing :shell
or :!man foobar (etc.) make the colours change, telling me I'm back "in
the terminal", and it's a fully-featured terminal, not the "dumb"
teletype-like terminal :shell gives me in gvim.

This is not to say that Martin's request would be invalid: it probably
isn't; it's just that I prefer it otherwise, and indeed AFAIK even
implementing Martin's proposal wouldn't force me to change my ways, thus
making us both happy.


Best regards,
Tony.
--
If the code and the comments disagree, then both are probably wrong.
-- Norm Schryer

Marcin Szamotulski

unread,
Sep 22, 2012, 3:29:16 AM9/22/12
to vim...@googlegroups.com
04:02 Sat 22 Sep , Tony Mechelynck wrote:
> This is not to say that Martin's request would be invalid: it probably
> isn't; it's just that I prefer it otherwise, and indeed AFAIK even
> implementing Martin's proposal wouldn't force me to change my ways, thus
> making us both happy.
That's why I like it so much, some times I also prefer to run a command
in a real shell (for example interactive ones requires that).

Thank you Marc for the list of plugins, I have to look at them more
closely.

I added it as a plugin: http://www.vim.org/scripts/script.php?script_id=4224
and also I added a reference in Vim wiki: http://vim.wikia.com/wiki/Append_output_of_an_external_command
(in the see also section)

As for the history: it is enough to add "call histdel(':', -1)" to the
command, i.e.
:call system(cmd)|call histdel(':', -1)

Best regards,
Marcin

Ben Fritz

unread,
Sep 24, 2012, 11:18:51 AM9/24/12
to vim...@googlegroups.com, gary...@spocom.com
On Friday, September 21, 2012 8:59:39 PM UTC-5, Gary Johnson wrote:
>
>
> I also found that ":echo system('..." works well on Windows: it
>
> avoids the new Command Prompt window when using gvim

If only! If you pay close attention or run a command which takes long enough you will see the command window flash briefly. I guess it immediately disappears without asking you to press enter to continue, which is nice, but still lets you see the output unlike using :!start.
Reply all
Reply to author
Forward
0 new messages