如何在命令中使用别名?

Cra*_*lus 4 vim alias filenames bashrc

aliases我在我的文件中创建了.bashrc各种经常使用的长路径,但我似乎无法在内部vim或通过诸如find或 之类的命令使用它们grep
例如,以下:
db
在 cli 中可以cd /some/very/long/path/db
,但在 vim 中:
:e db/file.java
或在命令行上:grep -r string db不起作用。
这是如何固定的?

小智 5

您可以为该目录设置环境变量。

# 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
Run Code Online (Sandbox Code Playgroud)

然后你可以在 Vim 中使用导出的变量,如下所示:

:e $DB/file.java
Run Code Online (Sandbox Code Playgroud)

在你的 shell 中:

grep -r string $DB
Run Code Online (Sandbox Code Playgroud)

Vim 和 bash 的变量替换工具完全彼此独立。Vim 只是以类似于 bash(和许多其他 shell)的方式替换环境变量。