即使我已经将vi
别名为vim
,这个返回代码还是很奇怪。
如果有人能解释一下原因,我会非常感激。
以下是我的命令和结果,请查看。
which vi
returns/usr/bin/vi
which vim
returns/usr/bin/vim
ls -al /usr/bin/vi /usr/bin/vim
returnslrwxr-xr-x 1 root wheel 3 Dec 15 03:34 /usr/bin/vi -> vim -rwxr-xr-x 1 root wheel 1745984 Dec 10 18:03 /usr/bin/vim
cat ~/.vimrc
returnsset nocompatible silent! unmap <C-E>
vim
then:q
to quit immediately. Thenecho $?
returns0
vi
then:q
to quite immediately. But problem is here,echo $?
returns1
- And if second line in
.vimrc
, i.e.silent! unmap <C-E>
, is removed,vi
,:q
,echo $?
returns0
vi
then:version
printsVIM - Vi IMproved 7.4 (2013 Aug 10, compiled Oct 5 2016 16:04:34) Included patches: 1-898 Compiled by root@apple.com Normal version without GUI. Features included (+) or not (-): +acl +cindent -conceal +digraphs -farsi -gettext +libcall +mksession -mouse_netterm -mzscheme -profile +scrollbind +syntax +textobjects +visualextra -X11 -arabic -clientserver +cryptv -dnd +file_in_path -hangul_input +linebreak +modify_fname -mouse_sgr +netbeans_intg +python/dyn +signs +tag_binary +title +viminfo -xfontset +autocmd -clipboard +cscope -ebcdic +find_in_path +iconv +lispindent +mouse -mouse_sysmouse +path_extra -python3 +smartindent +tag_old_static -toolbar +vreplace -xim -balloon_eval +cmdline_compl +cursorbind -emacs_tags +float +insert_expand +listcmds -mouseshape -mouse_urxvt -perl +quickfix -sniff -tag_any_white +user_commands +wildignore -xsmp -browse +cmdline_hist +cursorshape +eval +folding +jumplist +localmap -mouse_dec +mouse_xterm +persistent_undo +reltime +startuptime -tcl +vertsplit +wildmenu -xterm_clipboard +builtin_terms +cmdline_info +dialog_con +ex_extra -footer -keymap -lua -mouse_gpm +multi_byte +postscript -rightleft +statusline +terminfo +virtualedit +windows -xterm_save +byte_offset +comments +diff +extra_search +fork() -langmap +menu -mouse_jsbterm +multi_lang +printer +ruby/dyn -sun_workshop +termresponse +visual +writebackup -xpm system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc" user exrc file: "$HOME/.exrc" fall-back for $VIM: "/usr/share/vim" Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 Linking: gcc -L/usr/local/lib -o vim -lm -lncurses -liconv
I had tried
iTerm
,Terminal
, changed shell tobash
,zsh
,fish
. Remove first line,set nocompatible
, in.vimrc
. But they all returned this result.
如果您需要更多关于我的电脑的配置信息,请留言,我会提供。
谢谢!
更新
因为我在当前shell基础上开了一个新的shell,比如通过命令zsh
,bash
。它忽略了我的.zshrc
/.bash_profile
。
因此,$PATH
不包括/usr/local/bin
。然后,我使用默认的MacOS /usr/bin/vim
版本,而不是Homebrew的vim
8.0版本,因为which vim
指向了默认的MacOS版本。
尝试通过command-T
打开新的shell,并确保which vim
返回/usr/local/bin/vim
,即Homebrew的版本。vi
,:q
,echo $?
输出了预期的结果0
。
这解决了退出vi
后代码1的问题,这影响了git commit
命令等等。但我仍然不明白为什么MacOS的默认版本vi
会造成这种意外的行为。
vi
后,shell是干净的。我通过echo $?
手动检查了上一个命令的退出代码,并得到了结果。 - transang~/.vim
文件夹了。那里有很多插件。仅编辑~/.vimrc
是不够的。 - transang