Bash – How to use aliases in commands

aliasbashrcfilenamesvim

I have created aliases in my .bashrc for various frequently used long paths but I can not seem to be able to use them inside vim or with commands such as find or grep.
E.g the following:
db
in cli does cd /some/very/long/path/db
But in vim this:
:e db/file.java
or on the command line: grep -r string db do not work.
How is this fixed?

Best Answer

You can set an environmental variable for that directory.

# Making the variable name consist entirely of capital letters makes the
# variable less likely to conflict with other variables in scripts. You can
# make the variable name consist of lowercase letters but you may run
# into problems. 
export DB=/some/very/long/path/db

Then you can use the exported variable in Vim as such:

:e $DB/file.java

and in your shell as such:

grep -r string $DB

The variable-substitution facilities of Vim and bash are entirely independent from each other. Vim just happens to substitute environmental variables in a manner similar to bash (and many other shells).

Related Question