MacVim Open File In Existing Window

前端 未结 7 1094
我在风中等你
我在风中等你 2020-12-23 02:20

Is there a way to set up MacVim to open a new file in the current window in a running MacVim instance? I currently have the MacVim preference \"Open new files in a new tab i

7条回答
  •  长情又很酷
    2020-12-23 02:32

    @Björn Winckler's answer shows you how to do it for files opened through finder and other OS opening mechanisms.

    If you want it to work with the mvim command find the mvim file and changes the lines at the bottom from

    if [ "$gui" ]; then
        # Note: this isn't perfect, because any error output goes to the
        # terminal instead of the console log.
        # But if you use open instead, you will need to fully qualify the
        # path names for any filenames you specify, which is hard.
        exec "$binary" -g $opts ${1:+"$@"}
    else
        exec "$binary" $opts ${1:+"$@"}
    fi
    

    to

    if [ "$gui" ]; then
      # Note: this isn't perfect, because any error output goes to the
      # terminal instead of the console log.
      # But if you use open instead, you will need to fully qualify the
      # path names for any filenames you specify, which is hard.
    
      #make macvim open stuff in the same window instead of new ones
      if $tabs && [[ `$binary --serverlist` = "VIM" ]]; then
        exec "$binary" -g $opts --remote ${1:+"$@"}
      else
        exec "$binary" -g $opts ${1:+"$@"}
      fi
    else
      exec "$binary" $opts ${1:+"$@"}
    fi
    

    This will make all files opened from the command line open in the same window as well.

    Also if you would like the file to open the same buffer if that file is already open in stead of splitting or adding a new tab

    au VimEnter,BufWinEnter * NERDTreeFind to your gvimrc (so not to interfere with your regular vim)

    (this last part requires you to have NERDTree installed)

提交回复
热议问题