Call bash function using vim external command

后端 未结 4 1968
既然无缘
既然无缘 2021-01-13 22:00

I use vim\'s :! external command function all the time, usually providing % as an argument to the shell command. For example :

:!psql -f %

4条回答
  •  时光说笑
    2021-01-13 22:39

    This answer assumes your vim isn't actually using bash to invoke the remote commands - this can be tested by running :!echo $0 in vim.

    Specifically for vim, add:

    set shell=/bin/bash
    

    to your .vimrc.


    In general, there's two strategies I've found to sometimes work when trying to get other programs to invoke my preferred shell:

    export SHELL=/bin/bash
    

    in eg. the .profile file, or:

    ln -fsn /bin/bash /bin/sh
    

    which updates the sh symlink to point to bash instead.

    On many systems (certainly Ubuntu), /bin/sh is a symlink to a sh-compatible shell (such as bash), rather than the sh shell itself. Given this fact, some programs (I've seen this behaviour in GHC) seem to invoke /bin/sh, so changing where it points to will cause the programs to use bash instead.

提交回复
热议问题