vim and bash

42 views
Skip to first unread message

Nicolas Aggelidis

unread,
Dec 3, 2008, 3:09:21 AM12/3/08
to vim...@googlegroups.com
hi guys,

in vim when i try to do something like this:

:!ls

i get==>> cannot execute shell /usr/local/bin/bash which is logical
since my bash is at /bin/bash. Is there anyway to point vim to the
correct path?

thanks in advance,
nicolas

Cory Echols

unread,
Dec 3, 2008, 7:20:09 AM12/3/08
to vim...@googlegroups.com

You can explicitly set the 'shell' option to /bin/bash. Vim gets it's
default from the $SHELL environment variable. Some vim init script
might be overwriting the default with a bad value. You can use
":verbose set shell" to find out where that might be happening.

Nicolas Aggelidis

unread,
Dec 3, 2008, 8:06:51 AM12/3/08
to vim...@googlegroups.com
thank you Cory!

the "verbose set shell", saved my day!

yosi izaq

unread,
Dec 7, 2008, 5:17:13 AM12/7/08
to vim...@googlegroups.com
On Wed, Dec 3, 2008 at 3:06 PM, Nicolas Aggelidis <n.agg...@gmail.com> wrote:

thank you Cory!

the "verbose set shell", saved my day!

So how do I explicitly set the VIM shell variable?

10x,
Yosi

 

Ben Schmidt

unread,
Dec 7, 2008, 8:40:43 AM12/7/08
to vim...@googlegroups.com

Technically, it's an option in Vim, not a variable.

:set shell=/bin/bash

(put it in your .vimrc or something).

To set the $SHELL environment variable from which Vim automatically sets
its shell option when it starts up, you have to do something like

export SHELL=/bin/bash

or

setenv SHELL /bin/bash

in your shell login/initialisation scripts (~/.profile or ~/.login
probably). See your shell man page for the gory details.

It is odd for these values to be wrong, though, if your logins are
actually working. If something is not working, it is more likely that
some rogue Vim script is changing the option or shell script is setting
environment variable, when it shouldn't.

Ben.

yosi izaq

unread,
Dec 10, 2008, 10:22:54 AM12/10/08
to vim...@googlegroups.com
On Sun, Dec 7, 2008 at 3:40 PM, Ben Schmidt <mail_ben...@yahoo.com.au> wrote:

yosi izaq wrote:
> On Wed, Dec 3, 2008 at 3:06 PM, Nicolas Aggelidis <n.agg...@gmail.com
> <mailto:n.agg...@gmail.com>> wrote:
>
>
>     thank you Cory!
>
>     the "verbose set shell", saved my day!
>
>
> So how do I explicitly set the VIM shell variable?

Technically, it's an option in Vim, not a variable.

:set shell=/bin/bash

(put it in your .vimrc or something).

That's good to know.
One last Q, Is it possible for VIM to "recognize" my aliases, such as I have in my .aliases for example?- (in bash I simply source them of course)

Thanks,
Yosi.
 

Gary Johnson

unread,
Dec 10, 2008, 1:06:03 PM12/10/08
to vim...@googlegroups.com
On 2008-12-10, yosi izaq wrote:

> One last Q, Is it possible for VIM to "recognize" my aliases, such as I have
> in my .aliases for example?- (in bash I simply source them of course)

Vim doesn't know anything about how a shell invokes a command,
including whether that command is a built-in, an alias, a function
or a file. What you really want to know is whether aliases can be
used by a shell invoked from vim.

Bash "normally" sources ~/.bashrc only if it is run as an
interactive shell. This improves the performance of the shell when
it is run in non-interactive mode, where aliases are usually not
used. If you want the shell invoked from vim to see your aliases,
you can either tell vim to always invoke the shell in interactive
mode or tell the shell to always source ~/.bashrc even when not in
interactive mode.

For the former, I think (untested) that adding "-i" to
'shellcmdflag' will work, e.g.,

set shcf=-i\ -c

For the latter, you'll need to set the appropriate environment
variable in your ~/.profile or ~/.bash_profile. See the bash man
page, especially the INVOCATION section. I think the variable you
want is BASH_ENV.

HTH,
Gary

yosi izaq

unread,
Dec 11, 2008, 8:54:14 AM12/11/08
to vim...@googlegroups.com


On Wed, Dec 10, 2008 at 8:06 PM, Gary Johnson <gary...@spk.agilent.com> wrote:

On 2008-12-10, yosi izaq wrote:

> One last Q, Is it possible for VIM to "recognize" my aliases, such as I have
> in my .aliases for example?- (in bash I simply source them of course)

Vim doesn't know anything about how a shell invokes a command,
including whether that command is a built-in, an alias, a function
or a file.  What you really want to know is whether aliases can be
used by a shell invoked from vim.

Bash "normally" sources ~/.bashrc only if it is run as an
interactive shell.  This improves the performance of the shell when
it is run in non-interactive mode, where aliases are usually not
used.  If you want the shell invoked from vim to see your aliases,
you can either tell vim to always invoke the shell in interactive
mode or tell the shell to always source ~/.bashrc even when not in
interactive mode.

For the former, I think (untested) that adding "-i" to
'shellcmdflag' will work, e.g.,

  set shcf=-i\ -c

 
I tried that, and then invoked !ls and got the following errors:
/bin/bash: - : invalid option
Usage:  /bin/bash [GNU long option] [option] ...
        /bin/bash [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --protected
        --rcfile
        --rpm-requires
        --restricted
        --verbose
        --version
        --wordexp
Shell options:
        -irsD or -c command or -O shopt_option          (invocation only)
        -abefhkmnptuvxBCHP or -o option

shell returned 2 

I'll read more about the 2nd option of instructing bash to source .bashrc.

Thanks,
Yosi

Gary Johnson

unread,
Dec 11, 2008, 11:40:58 AM12/11/08
to vim...@googlegroups.com
On 2008-12-11, yosi izaq wrote:
> On Wed, Dec 10, 2008 at 8:06 PM, Gary Johnson <gary...@spk.agilent.com>wrote:
>
> >
> > On 2008-12-10, yosi izaq wrote:
> >
> > > One last Q, Is it possible for VIM to "recognize" my aliases, such as I
> > have
> > > in my .aliases for example?- (in bash I simply source them of course)
> >
> > Vim doesn't know anything about how a shell invokes a command,
> > including whether that command is a built-in, an alias, a function
> > or a file. What you really want to know is whether aliases can be
> > used by a shell invoked from vim.
> >
> > Bash "normally" sources ~/.bashrc only if it is run as an
> > interactive shell. This improves the performance of the shell when
> > it is run in non-interactive mode, where aliases are usually not
> > used. If you want the shell invoked from vim to see your aliases,
> > you can either tell vim to always invoke the shell in interactive
> > mode or tell the shell to always source ~/.bashrc even when not in
> > interactive mode.
> >
> > For the former, I think (untested) that adding "-i" to
> > 'shellcmdflag' will work, e.g.,
> >
> > set shcf=-i\ -c
> >
>
>
> I tried that, and then invoked !ls and got the following errors:
> /bin/bash: - : invalid option

Hmm. I just tried it with ksh and got the same results. A command
like this one,

ksh -i -c 'ct ls'

works fine from the command line, so those options are OK. (ct is
an alias for cleartool.) I don't know what it is that causes

set shellcmdflag=-i\ -c

to fail. However, this variation does work:

set shellcmdflag=-ic

Regards,
Gary

Matt Wozniski

unread,
Dec 11, 2008, 10:12:11 PM12/11/08
to vim...@googlegroups.com
On Thu, Dec 11, 2008 at 11:40 AM, Gary Johnson wrote:
>
> On 2008-12-11, yosi izaq wrote:
>
>> On Wed, Dec 10, 2008 at 8:06 PM, Gary Johnson wrote:
>>
>> > For the former, I think (untested) that adding "-i" to
>> > 'shellcmdflag' will work, e.g.,
>> >
>> > set shcf=-i\ -c
>>
>> I tried that, and then invoked !ls and got the following errors:
>> /bin/bash: - : invalid option
>
> set shellcmdflag=-i\ -c
>
> to fail. However, this variation does work:
>
> set shellcmdflag=-ic

Quoting.

~> "bash" "-i -c" "ls"
bash: - : invalid option

~> "bash" "-i" "-c" "ls"
(works as desired)

setting shellcmdflag to '-i -c' makes that be passed as one argument
to bash, so bash sees "-" meaning "start some short flags", then "i"
meaning interactive, then " " - and it barfs there.

~Matt

yosi izaq

unread,
Dec 14, 2008, 5:00:54 AM12/14/08
to vim...@googlegroups.com
Following your responses I was able to make VIM recognize my bash aliases - a huge time saver.

Thank you guys!
Yosi
Reply all
Reply to author
Forward
0 new messages