Hãy thử thêm dòng này để ~/.vimrc
của bạn:
set shell=/bin/bash\ -i
Sau đó vim
sẽ sử dụng một vỏ tương tác (-i
) mà đọc từ ~/.bashrc
, theo mặc định. Xem :h shell
để biết thêm thông tin về shell
.
Tôi thấy điều này về bản chất giống như các câu trả lời trước mà bạn nói không hoạt động. Vui lòng thử phiên mẫu dưới đây trên máy của bạn để xem bạn có kết quả tương tự hay không (và đăng bất kỳ lỗi/phân kỳ nào từ kết quả bạn thấy trong mẫu).
$ cat .bash_aliases
alias test_alias="echo test alias"
test_func() {
echo test func
}
$ vim
[vim]:set shell=/bin/bash
[vim]:!type test_alias
/bin/bash: line 0: type: test_alias: not found
shell returned 1
Press ENTER or type command to continue
[vim]:!type test_func
/bin/bash: line 0: type: test_func: not found
shell returned 1
Press ENTER or type command to continue
[vim]:set shell=/bin/bash\ -i
[vim]:!type test_alias
test_alias is aliased to `echo test alias'
Press ENTER or type command to continue
[vim]:!type test_func
test_func is a function
test_func()
{
echo test func
}
Press ENTER or type command to continue
Đối với lý do tại sao nó không được làm việc để bắt đầu với, khi bash
chỉ đơn giản là chạy (ví dụ:không tương tác cũng không đăng nhập; mặc định cho vim và hầu hết các mục đích khác), nó đọc bất cứ tập tin được quy định tại $BASH_ENV
:
When bash is started non-interactively, to run a shell script, for
example, it looks for the variable BASH_ENV in the environment, expands
its value if it appears there, and uses the expanded value as the name
of a file to read and execute. Bash behaves as if the following com‐
mand were executed:
if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
but the value of the PATH variable is not used to search for the file
name.
Bằng cách thêm -i
, chúng tôi làm cho vỏ tương tác và do đó nó nó đọc ~/.bashrc
:
When an interactive shell that is not a login shell is started, bash
reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if
these files exist. This may be inhibited by using the --norc option.
The --rcfile file option will force bash to read and execute commands
from file instead of /etc/bash.bashrc and ~/.bashrc.
Các Các tệp *profile
được đọc khi bắt đầu trình bao đăng nhập:
When bash is invoked as an interactive login shell, or as a non-inter‐
active shell with the --login option, it first reads and executes com‐
mands from the file /etc/profile, if that file exists. After reading
that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order, and reads and executes commands from the first one that
exists and is readable. The --noprofile option may be used when the
shell is started to inhibit this behavior.
Worth lưu ý rằng 'rtr' là một hàm, không phải là một bí danh. – richo
Khi bạn đặt 'set shell =/bin/bash \ -i' vào' ~/.vimrc' và mở 'vim', nó có giữ nguyên không? (': set shell' sẽ cho bạn biết bạn đang sử dụng shell nào). Có vẻ như bạn đang gọi nó bằng 'vi' (hoặc nó là một' vi' thực sự?), Có lẽ bạn cần sử dụng '~/.virc' để thay thế. – Kevin
Kevin: Nó in ra "/ bin/bash -i" khi tôi làm: đặt shell, nhưng ngay sau khi tôi thử chạy chức năng của tôi: bash: rgr: lệnh không tìm thấy [2] + Ngưng vim -u ~ /.vimrc – ashgromnies