Vi 是 vim 的别名,但以代码 1 退出 [英] Vi is aliased to vim but exit with code 1
问题描述
即使我将 vi
别名为 vim
,这也是一个奇怪的返回码.
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
返回/usr/bin/vi
哪个vim
返回/usr/bin/vim
ls -al/usr/bin/vi/usr/bin/vim
返回
lrwxr-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
返回
set nocompatible
silent! unmap <C-E>
vim
然后 :q
立即退出.然后 echo $?
返回 0
vim
then :q
to quit immediately. Then echo $?
returns 0
vi
然后 :version
打印
VIM - 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
我试过iTerm
、Terminal
,把shell改成bash
、zsh
、鱼代码>.删除
.vimrc
中的第一行 set nocompatible
.但是他们都返回了这个结果.
I had tried iTerm
, Terminal
, changed shell to bash
, 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.
提前致谢.
更新
因为我打开了基于当前shell的新shell,通过像zsh
、bash
这样的命令.它忽略了我的 .zshrc
/.bash_profile
.
Because I opened new shell based on the current shell, via command like zsh
, bash
. It ignored my .zshrc
/.bash_profile
.
因此,$PATH
不包括 /usr/local/bin
.然后,而不是使用自制软件 vim
8.0 版本.which vim
指向默认的 MacOS /usr/bin/vim
版本.
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.
尝试通过command-T
打开新的shell并确保which vim
返回/usr/local/bin/vim
,即自制软件的版本.vi
, :q
, echo $?
回显预期结果 0
.
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
.
这解决了我退出 vi
后退出代码 1 的问题,这影响了 git commit
命令 ..etc.但我仍然不明白为什么 vi
的默认 MacOS 版本会导致这种意外行为
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
推荐答案
对于 Vim,您不需要设置为 'nocompatible',因为这是默认设置.
You don't need to set to 'nocompatible' to Vim because this is the default setting.
我在我的 MacOS 中删除了这个功能并且工作正常并且退出状态为 0,写入或不写入文件.
I remove this feature in my MacOS and works fine and with exit status 0, writing or not writing files.
注意:是 MacOS 'vi' 是指向 'Vim' 的链接(而 'awk' 实际上是 'gawk')
Note: is MacOS 'vi' is a link to 'Vim' (and 'awk' is actually 'gawk')
结论:你可以使用
silent! unmap <C-E>
在您的 .vimrc 文件中,vim 可能不会出现错误退出.
in your .vimrc file and vim may not exit with error.
这篇关于Vi 是 vim 的别名,但以代码 1 退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!