我来晚了,但我有一个建议。
首先,我同意@Herbert - 通常很少有理由运行多个 Vim 实例(控制台或其他)。将事物保存在一个实例中的好处实在是太大了。但是,我认为有必要混入-c
;虽然我看不出有必要自己做:D。
我能看到获得此功能的最佳方法是使用--remote-send
vim 的功能而不是--remote-silent
. 然而,这意味着一些 shell 脚本:
#!/bin/bash
function resolveFile
{
if [ -f "$1" ]; then
echo $(readlink -f "$1")
else
echo "$1"
fi
}
function gg
{
local opts=$(getopt -o c: --long command: -n "gg" -- "$@")
if [ $? != 0 ]; then return 1; fi
eval set -- "$opts"
cmd=""
while :
do
case "$1" in
-c|--command)
cmd="$2"
shift 2
;;
--) shift
break
;;
esac
done
if [[ -n "$cmd" ]]; then
if [[ -n "${1-}" ]]; then
cmd=":e $(resolveFile $1)<cr>$cmd<cr>"
else
cmd="$cmd<cr>"
fi
shift 1
fi
files=""
for f in $@
do
files="$files $(resolveFile $f)"
done
cmd="$cmd:args! $files<cr>"
gvim --remote-send "$cmd"
}
我只是对它进行了少量测试,但您应该能够执行以下操作:
gg -c G file1 file2 file3 file4
那应该编辑 file1
并移动到它的底部。然后它还应该将file2
,file3
和添加file4
到 args 列表中,以便您可以执行诸如:bnext
. 它还应该恢复到与--remote-silent
不提供-c
.
我真的认为值得跳过这些障碍,以便将您的命令行体验与单个 Vim 实例正确集成。把所有东西都放在一个地方实在是太甜蜜了,不能放弃。