Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:
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?

share|improve this question

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).

share|improve this answer

Aliases let you give a short name to a command and some arguments. They are only expanded where a command is expected. You can't use them to abbreviate the path to a file.

Furthermore .bashrc is only read by interactive shells, so nothing that you define there will be available in a command typed in Vim.

If you want to have a shortcut to a file or directory, create a symbolic link to it.

ln -s /some/very/long/path/db ~/db
grep -r string ~/db
vim ~/db/file.java

You can define environment variables to abbreviate any string. Environment variable definitions go into ~/.profile. Not every program expands them, but Vim does when you open a file with :e (among other things).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.