Vim can not execute unix command with :! due to shell changing

bashtcshvimvimrc

Our company uses red hat linux system and allocate everyone an account in /home. Unfortunately, our system is using tsch, which is not favorable for me. Moreover, as I do not have the super user permission, I can not use the chsh command to change to bash for myself. Even worse, ypchsh is also unavailable for me. So, at last, I add the following lines into the .cshrc:

    bash
    echo $0

and configure the .bashrc appropriately (copying from the original .cshrc and fixing necessary syntax error). Now the apparent shell become bash (as can be shown from "echo $0" command).

Now the problem comes up:

When I use vim to edit a cpp file (e.g., Hello_World), and use ":!g++ -g Hello_World.cpp -o hw.out" in vim to compile the file, no result will be shown, and vim is quit with "bash" shown (as when a terminal is open), but without the usual "hit a key" to get back to my work in vim. In the Hello_World.cpp folder, there is a .Hello_World.cpp.swp file, but not hw.out. When vim Hello_World.cpp again, it turns out that this cpp file has been open.

However, if I g++ the cpp file in the folder but not using vim and :!, everything is OK. In fact, :! now seems to be illegal for vim.

If I use the original tcsh, everything is also OK.

How could I fix this curious error?

Thank you for your kind help in advance.

qing

BTW: I prefer bash to tcsh primarily due to its convenience of HISTIGNORE and HISTCONTROL, although tcsh also has histdup setting.

I found the following a little helpful but still not satisfactory for my problem.

How to run Unix commands from within Vim?

Best Answer

Put this in your .login script:

setenv SHELL /bin/bash
exec bash -l

The first line sets the SHELL environment variable. The second line replaces the tcsh with bash, but tells it to run as a login shell (so bash will process your .profile etc). You could add a -i option to make it interactive; it should not be necessary.

Related Question