假设我打开了几个 gvim 窗口,每个窗口中可能打开了几个文件。
在命令行中我想要一个函数或别名,比如 gvimUniq
如果文件在其中一个窗口中打开,将把那个窗口带到前面,否则创建一个新窗口该文件已打开。
最佳答案
我已经习惯了使用单个 gvim 窗口运行并使用选项卡打开文档:
gvim() {
local -u servername="${HOSTNAME}_${LOGNAME}"
local -u currentservers=$(command gvim --serverlist)
if (( $# == 0 )); then
if [[ $currentservers == *${servername}* ]]; then
command gvim --servername "$servername" --remote-send '<Esc>:tabe<CR>' || command gvim
else
command gvim --servername "$servername" || command gvim
fi
else
# http://stackoverflow.com/questions/936501/let-gvim-always-run-a-single-instance
local vi_options=()
while [[ $1 == -* ]]; do
[[ $1 != -- ]] && vi_options+=("$1")
shift
done
if [[ $currentservers == *${servername}* ]]; then
command gvim "${vi_options[@]}" --servername "$servername" --remote-tab-silent "$@" || command gvim "$@"
else
command gvim "${vi_options[@]}" --servername "$servername" "$@" || command gvim "$@"
fi
fi
}
关于bash - 如果文件已经打开,gvim 打开实例,否则创建新窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23614480/