Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I open a new file from Terminal to a tab instead of a new window on MacVim?

Tags:

vim

macvim

I moved mvim to /usr/local/bin, so from Terminal if I type mvim file.html, then MacVim will open in a new window and open the file file.html.

But if I open another file from Terminal, then it will open another MacVim window.

Is it possible open the new file as a new tab on MacVim?

I currently have the MacVim setting as

Open files from application: in the current window
    with a tab for each file

But that only open new files in a new tab only if I open the file from MacVim (not running mvim from the Terminal).

like image 383
hobbes3 Avatar asked Feb 01 '12 18:02

hobbes3


People also ask

How do I open a new tab in Mac terminal?

In the Terminal app on your Mac, do one of the following: Press Command-T. Choose Shell > New Tab > New Tab with Profile. The name of the profile that opens is concatenated to the end of the New Tab with Profile menu item.

How do I open a separate window in Vim?

To open a new VIM window next to the existing one, press <Ctrl>+<w> then press <v>. You can move to the left window again by pressing <Crtl>+<w> and then pressing <h>. To open a new VIM window on the bottom of the currently selected window, press <Ctrl>+<w> then press <s>.

How do I open a new tab in Vim?

Probably the easiest to remember is to run the :tabnew command while in normal mode. This will open a new tab with an empty buffer. If you want to edit a file in the new tab, you can run :tabnew filename and Vim will load the file in the new tab.

How do I use tabs in Vim?

To directly move to first tab or last tab, you can enter the following in command mode: :tabfirst or :tablast for first or last tab respectively. To move back and forth : :tabn for next tab and :tabp for previous tab. You can list all the open tabs using : :tabs. To open multiple files in tabs: $ vim -p source.


1 Answers

This hack should work, but it may be frustrating to maintain every time that MacVim is updated. It requires you to edit the mvim script. This seems to be a longstanding and known issue.

mvim `which mvim`

## Add the following line to the top of the file, below the commented section:

tabs=true

## Replace the `if` structure at the bottom of the file with the following:

# 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
like image 199
Ted Kalaw Avatar answered Oct 06 '22 00:10

Ted Kalaw