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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Alistair MacDonald
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?

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Tony Mechelynck
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.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Adam Horner
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.


On 23 Jan 2016, at 23:44, Tony Mechelynck <[hidden email]> wrote:

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.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...