【问题标题】:gvim open instance if file already open, otherwise create new window如果文件已经打开,gvim 打开实例,否则创建新窗口
【发布时间】:2014-06-30 03:17:36
【问题描述】:

假设我打开了几个 gvim 窗口,每个窗口中都可能打开了几个文件。

在命令行中,我想要一个函数或别名,比如gvimUniq,如果文件在其中一个窗口中打开,则会将该窗口置于最前面,否则创建一个打开该文件的新窗口。

【问题讨论】:

    标签: bash vim


    【解决方案1】:

    我已经习惯了使用单个 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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多