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).
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.
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>.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With