How do I: Open file in same window (new tab) and GOTO line?

58 views
Skip to first unread message

Alistair MacDonald

unread,
Jan 22, 2016, 3:09:43 PM1/22/16
to vim_mac
I have an alias setup to open a file in the same window, like so:

alias edit="open -a MacVim.app $1"
# edit ./myfile.txt

But this does not work for the goto line/function. I get the following error:

The file /Users/me/+123 does not exist.

To get around this I am using a separate alias, like this:

alias edit@="mvim $1 $2"
# edit@ +123 ./myfile.txt

But I would like to use the `edit` alias to both. Is there a way I can do this using the `open -a MacVim.app` syntax?

Tony Mechelynck

unread,
Jan 23, 2016, 6:44:55 PM1/23/16
to vim_mac
I assume that by “window” you mean “Vim instance”, since in Vim parlance there may be one or more (plit) windows within a tab but not the opposite. There are also one or more tabs (or tab pages) in one “Vim screen” (or Vim instance) but not the opposite.

I don't run a Mac, but in general to start Vim with three tab pages, one file in each, you would invoke it as

vim -p file1.ext file2.ext file3.ext

This should work with any "vim flavour" such as vim, gvim, MacVim, etc. You may want to vary it according to the peculiarities of MacOsX.

See ":help -p"

To open the file at a specific line, I expect that prefixing the filename with +123 (for line 123), followed by a space, should work, but I haven't yet tested it: so to open several files, each in its tab, and each at a specific line, you could do

vim -p +123 file1.ext +456 file2.txt +789 file3.txt

but I haven't tested it.

See ":help +cmd"

In general, if you set the 'viminfo' option correctly, Vim will remember where the cursor was in a given file when it was last used, and with the proper autocommand (as in $VIMRUNTIME/vimrc.example.vim lines 73-79, so if you source that from your vimrc you've got it) the file will be reopened at that same position (or at line 1 if no position was remembered for the file).

Best regards,
Tony.

Adam Horner

unread,
Jan 25, 2016, 10:26:04 AM1/25/16
to vim...@googlegroups.com
Alistair,

If you have a look in the download bundle for MacVim you will see a command line tool that is distributed with it called mvim.

Put mvim in a standard location that is on your PATH, on the mac a good default location is /usr/local/bin (chosen to work with as many flavours of the Mac OS as possible, including the latest).

mvim helps the MacVim binary get called in a completely compatible way with the unix counterpart such that you can then rely on the documentation, including Tony’s suggestions below.

Thanks,
Adam.


--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_mac+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages