Loading...

How to make the vim call function in .bashrc?

Answer #1 100 %

The problem is that Vim by default invokes a non-interactive shell, and .bashrc (where you've defined your add function) is only read for interactive shells.

You can instruct Vim to use an interactive shell:

:set shellcmdflag=-ic

This may make external command invocations slighly slower (due to the overhead in evaluating your Bash initializations).

Alternatively, you could define the function somewhere else, so it's always available (but there's no easy place like this; see man bash, esp. the INVOCATION section). Or turn the function into a separate script accessible from your PATH (e.g. ~/bin/add).

Answer #2 100 %

The problem is your function is limited to an interactive shell to execute it you have to do like this

:!bash -ic "add 1 2"

You’ll also like:


© 2022 CodeForDev.com -