shell - vimdiff 与交互式 shell

标签 shell vim

我的 .vimrc 中有 shellcmdflag=-ic 以使 shell 具有交互性 (这样做是为了读取别名')

设置此交互式选项后,shell 命令(在前面运行 !) 总是会让 vim 进入后台,就像按下 Ctrl-z 一样,我必须 fg 才能恢复 vim。

我可以通过 fg 让 vim 回到前面,但是这个交互式 shell 也破坏了 vimdiff

无论是通过 vimdiff 还是 :difft 进入 diff 模式,我都必须 fg 两次才能回到 vim,有时甚至会崩溃整个控制台..

下面是我的 vim :version

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled May  4 2012 04:21:49)
Included patches: 1-429
Modified by <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7a0a111d570c131757171b13140e1b13141f08093a1613090e09541b1613150e12541e1f18131b145415081d" rel="noreferrer noopener nofollow">[email protected]</a>
Compiled by buildd@
Huge version with GTK2 GUI.  Features included (+) or not (-):
+arabic +autocmd +balloon_eval +browse ++builtin_terms +byte_offset +cindent +clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments +conceal +cryptv +cscope +cursorbind +cursorshape
+dialog_con_gui +diff +digraphs +dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path +find_in_path +float +folding -footer +fork() +gettext -hangul_input +iconv +insert_expand +jumplist +keymap
+langmap +libcall +linebreak +lispindent +listcmds +localmap +lua +menu +mksession +modify_fname +mouse +mouseshape +mouse_dec +mouse_gpm -mouse_jsbterm +mouse_netterm -mouse_sysmouse +mouse_xterm +mouse_urxvt
+multi_byte +multi_lang -mzscheme +netbeans_intg +path_extra +perl +persistent_undo +postscript +printer +profile +python -python3 +quickfix +reltime +rightleft +ruby +scrollbind +signs +smartindent -sniff
+startuptime +statusline -sun_workshop +syntax +tag_binary +tag_old_static -tag_any_white +tcl +terminfo +termresponse +textobjects +title +toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo
+vreplace +wildignore +wildmenu +windows +writebackup +X11 -xfontset +xim +xsmp_interact +xterm_clipboard -xterm_save
system vimrc file: "$VIM/vimrc"
 user vimrc file: "$HOME/.vimrc"
  user exrc file: "$HOME/.exrc"
system gvimrc file: "$VIM/gvimrc"
 user gvimrc file: "$HOME/.gvimrc"
  system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12     -g -O2 -fstack-protect or --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1     -I/usr/include/tcl8.5  -D_REENTRANT=1  -D_THREAD_SAFE=1  -D_LARGEFILE64_SOURCE=1
Linking: gcc   -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -rdynamic -Wl,-export-dynamic  -Wl,-E  -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0   -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl  -L/usr/
lib -llua5.1  -Wl,-E  -fstack-protector -L/usr/local/lib  -L/usr/lib/perl/5.14/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python2.7/config -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -
Wl,-Bsymbolic-functions  -L/usr/lib -ltcl8.5 -ldl -lpthread -lieee -lm -lruby1.8 -lpthread -lrt -ldl -lcrypt -lm  -L/usr/lib

有人遇到同样的问题吗?

最佳答案

也许不要将 Vim 子 shell 设置为交互模式来获取别名,而是检查 .bashrc 中的 $VIM 环境变量:

if [[ $- = *i* || ! -z "$VIM" ]]; then
  # alias ll=...
fi

您需要explicitly tell bash获取 .bashrc 的源代码,因为它在非登录、非交互模式 (-c) 下不会获取任何内容。另外,alias expansion needs enabling 。在您的 .vimrc 中添加:

let $BASH_ENV = '~/.bashrc'
set shellcmdflag=-O\ expand_aliases\ -c

关于shell - vimdiff 与交互式 shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11980796/

相关文章:

linux - 用于在不同终端中运行脚本中的每个命令的 Shell 脚本

linux - 使用 grep 和 awk 过滤 ping 结果完全不起作用

vimscript - 使用自动命令检查新窗口的 win 和 buf 类型的可靠方法

linux - 如何在 Vim 中的行首和行尾添加/*?

vim - 如何在 vim 中使用 NERD Commenter -- 如何使用 <Leader> 键

windows - wget --content-disposition文件名上的转义字符

linux - 在多个文件 Linux 中搜索单词并将大写转换为小写

vim - 在 Vim 状态栏中,右键盘数字

vim - autocmd 文件类型与 ftplugin

eclipse - 在 Eclipse Helios 中安装 ShellEd 插件时出现问题