问题
This is a weird return code even I have aliased vi
by vim
.
I really appreciate if anyone could explain me why.
Check my commands and results below.
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.
If you need more config in my PC, please give a comment, I will provide it.
Thanks in advance.
Update
Because I opened new shell based on the current shell, via command like zsh
, bash
. It ignored my .zshrc
/.bash_profile
.
Thus, $PATH
does not include /usr/local/bin
. Then, instead of using homebrew vim
8.0 version. which vim
pointed to default MacOS /usr/bin/vim
version.
After trying opening open new shell by command-T
and ensure that which vim
returns /usr/local/bin/vim
, i.e. homebrew's version.
vi
, :q
, echo $?
echoed expected result 0
.
This solved my problem of exit code 1 after exiting vi
, this affected git commit
command ..etc. But I still do not understand why default MacOS version of vi
makes this unexpected behaviour
回答1:
You don't need to set to 'nocompatible' to Vim because this is the default setting.
I remove this feature in my MacOS and works fine and with exit status 0, writing or not writing files.
Note: is MacOS 'vi' is a link to 'Vim' (and 'awk' is actually 'gawk')
Conclusion: you may use
silent! unmap <C-E>
in your .vimrc file and vim may not exit with error.
来源:https://stackoverflow.com/questions/41719802/vi-is-aliased-to-vim-but-exit-with-code-1