コマンドにエイリアスを使用するには?

コマンドにエイリアスを使用するには?

aliases私のファイルに頻繁に使用されるさまざまな長いパスが生成されていますが、内部的にまたはなどのコマンドを介して.bashrc使用できないようです。たとえば、次のコマンドはcliでは動作しますが、vim:またはコマンドラインでは動作しません。この問題はどのように解決されますか?vimfindgrep

db
cd /some/very/long/path/db

:e db/file.java
grep -r string db

ベストアンサー1

このディレクトリの環境変数を設定できます。

# 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

その後、Vimからエクスポートされた変数を次のように使用できます。

:e $DB/file.java

シェルから:

grep -r string $DB

Vimとbashの変数置換ツールは互いに完全に独立しています。 Vimはbash(および他のいくつかのシェル)と同様の方法で環境変数を置き換えます。

おすすめ記事