MacVim Open file in existing window

Is there a way to configure MacVim to open a new file in the current window in an executable instance of MacVim? I currently have a MacVim preference for "Open new files in a new tab in the current window", but ideally I would just like to open new files like this: "e new_file" works without tabs.

My main motivation is that I currently use NERDTree and Bufexplorer for my workflow and don’t need tabs at all. I also use PeepOpen, which is awesome, except that it always opens files based on MacVim preferences, so best of all I can open it in the current MacVim window with a new tab.

+43
macvim tabs
Aug 13 '10 at 16:15
source share
7 answers
  • Update to MacVim 7.3
  • Go to General Settings
  • In the section "Open files from applications:" select "in the current window
  • In the drop-down menu under this option, select "and set arglist"
+48
Oct. 15 '10 at 18:10
source share

You can also add:

alias mvim='open -a MacVim'

to your .bash_profile

This seems like the easiest solution for me.

+25
Aug 14 '12 at 9:45
source share

You can also consider this issue when editing the main mvim script.

Improving mvim for MacVim

This modification is a little less serious and also works:

MacVim supports tabs, but unfortunately calling mvim several times from the command line opens several separate windows, instead of several tabs in the same window. I made the following changes to the mvim script to fix this.

Add the following line to the top of the file, under the comments section:

 tabs=true 

Replace the if structure at the bottom of the file as follows:

 # Last step: fire up vim. if [ "$gui" ]; then if $tabs && [[ `$binary --serverlist` = "VIM" ]]; then exec "$binary" -g $opts --remote-tab-silent ${1:+"$@"} else exec "$binary" -g $opts ${1:+"$@"} fi else exec "$binary" $opts ${1:+"$@"} fi 

(from Open MacVim tabs from the command line )

Obviously, this is also a bit suboptimal b / c, you will have to support hacking when you do the MacVim update. But they helped me collect some files from the terminal in the new Mac Vim tabs.

+14
Jan 10 '11 at 17:58
source share

I personally use such a command, having seen everything here and resorting to experimenting with the fact that

 mvim --help 

.

I found that

 mvim --remote-tab-silent foo.txt 

worked for me and then I soon added an alias to .profile . Yes, it's barfs, if you do not feed it with a file after the option, but who still opens an empty file without a name?

+13
May 29 '14 at 7:22
source share

@ Björn Winckler's answer shows how to do this for files opened through search engines and other OS opening mechanisms.

If you want it to work with the mvim command, find the mvim file and change the lines below

 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 cause all files opened from the command line to open in the same window.

Also, if you want the file to open the same buffer if this file is already open instead of splitting or adding a new tab

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

(this last part requires the installation of NERDTree)

+4
Aug 27 '12 at 16:23
source share

Here is how I did it:

VIM has a tabo command that makes the current tab the only tab. I added the following to my ~ / .vimrc:

 autocmd BufWinEnter,BufNewFile * silent tabo 

This makes it so that any time I create a new buffer or enter a new buffer, the current tab automatically becomes the only tab. This command does not affect my buffers, so the effect is exactly what I want: open the file in the current MacVim instance and not add new tabs.

+1
Aug 13 '10 at 18:17
source share

I found that Azriel answers big questions, but it does not work if the file does not exist. This small function does the same, but you can also create new files.

 mvim () { touch "$@" && open -a MacVim "$@"; } 

Just add it to .bash_profile . Then you can edit the new foo file as

 mvim foo 

and it will open in a new tab.

+1
May 21 '14 at 11:44
source share



All Articles