Open one window only with `mvim`

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Open one window only with `mvim`

Normen Müller
Hi,

I am not sure if this belongs to this list but I'll give it try, maybe one here knows the solution.

I am using MacVim with one window only. Switching buffers with `:ls`, `:b <number>`, or just `:b#`.

But when opening MacVim from a Terminal, the command `mvim <file>` opens  for each file a new window. But I want it to reuse the existing one  and just to open a new buffer within this window.

Maybe it's just a minor modification to the `mvim` script, or a startup option of MacVim. Anyway, I couldn't find the solution. Any suggestion?

Best, /nm

P.S. My `mvim` script:

#----------------------------------------------------------------------------
#!/bin/sh

if [ -z "$VIM_APP_DIR" ]
then
        myDir="`dirname "$0"`"
        myAppDir="$myDir/../Applications"
        for i in ~/Applications ~/Applications/vim $myDir $myDir/vim $myAppDir $myAppDir/vim /Applications /Applications/vim /Applications/Utilities /Applications/Utilities/vim; do
                if [ -x "$i/MacVim.app" ]; then
                        VIM_APP_DIR="$i"
                        break
                fi
        done
fi
if [ -z "$VIM_APP_DIR" ]
then
        echo "Sorry, cannot find MacVim.app.  Try setting the VIM_APP_DIR environment variable to the directory containing MacVim.app."
        exit 1
fi
binary="$VIM_APP_DIR/MacVim.app/Contents/MacOS/Vim"

# Next, peek at the name used to invoke this script, and set options
# accordingly.

name="`basename "$0"`"
gui=
opts=

# GUI mode, implies forking
case "$name" in m*|g*|rm*|rg*) gui=true ;; esac

# Restricted mode
case "$name" in r*) opts="$opts -Z";; esac

# vimdiff, view, and ex mode
case "$name" in
        *vimdiff)
                opts="$opts -dO"
                ;;
        *view)
                opts="$opts -R"
                ;;
        *ex)
                opts="$opts -e"
                ;;
esac

# Last step:  fire up vim.
# The program should fork by default when started in GUI mode, but it does
# not; we work around this when this script is invoked as "gvim" or "rgview"
# etc., but not when it is invoked as "vim -g".
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
#----------------------------------------------------------------------------

--
--
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/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Open one window only with `mvim`

Mohit Sharma



On Tue, Mar 4, 2014 at 10:14 AM, Normen Müller <[hidden email]> wrote:
Hi,

I am not sure if this belongs to this list but I'll give it try, maybe one here knows the solution.

I am using MacVim with one window only. Switching buffers with `:ls`, `:b <number>`, or just `:b#`.

But when opening MacVim from a Terminal, the command `mvim <file>` opens  for each file a new window. But I want it to reuse the existing one  and just to open a new buffer within this window.

Maybe it's just a minor modification to the `mvim` script, or a startup option of MacVim. Anyway, I couldn't find the solution. Any suggestion?

I'm not sure if there is an option to open it up in a buffer but you can use the --remote-tab option to open the file in another tab of already opened MacVim application.
 

Best, /nm

P.S. My `mvim` script:

#----------------------------------------------------------------------------
#!/bin/sh

if [ -z "$VIM_APP_DIR" ]
then
        myDir="`dirname "$0"`"
        myAppDir="$myDir/../Applications"
        for i in ~/Applications ~/Applications/vim $myDir $myDir/vim $myAppDir $myAppDir/vim /Applications /Applications/vim /Applications/Utilities /Applications/Utilities/vim; do
                if [ -x "$i/MacVim.app" ]; then
                        VIM_APP_DIR="$i"
                        break
                fi
        done
fi
if [ -z "$VIM_APP_DIR" ]
then
        echo "Sorry, cannot find MacVim.app.  Try setting the VIM_APP_DIR environment variable to the directory containing MacVim.app."
        exit 1
fi
binary="$VIM_APP_DIR/MacVim.app/Contents/MacOS/Vim"

# Next, peek at the name used to invoke this script, and set options
# accordingly.

name="`basename "$0"`"
gui=
opts=

# GUI mode, implies forking
case "$name" in m*|g*|rm*|rg*) gui=true ;; esac

# Restricted mode
case "$name" in r*) opts="$opts -Z";; esac

# vimdiff, view, and ex mode
case "$name" in
        *vimdiff)
                opts="$opts -dO"
                ;;
        *view)
                opts="$opts -R"
                ;;
        *ex)
                opts="$opts -e"
                ;;
esac

# Last step:  fire up vim.
# The program should fork by default when started in GUI mode, but it does
# not; we work around this when this script is invoked as "gvim" or "rgview"
# etc., but not when it is invoked as "vim -g".
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
#----------------------------------------------------------------------------

--
--
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/groups/opt_out.

--
--
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/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: Open one window only with `mvim`

Normen Müller
In reply to this post by Normen Müller
Hi, never mind, the solution is at http://stackoverflow.com/questions/3478755/macvim-open-file-in-existing-window. Best, /nm

On Tuesday, March 4, 2014 7:14:49 PM UTC+1, Normen Müller wrote:

> Hi,
>
> I am not sure if this belongs to this list but I'll give it try, maybe one here knows the solution.
>
> I am using MacVim with one window only. Switching buffers with `:ls`, `:b <number>`, or just `:b#`.
>
> But when opening MacVim from a Terminal, the command `mvim <file>` opens  for each file a new window. But I want it to reuse the existing one  and just to open a new buffer within this window.
>
> Maybe it's just a minor modification to the `mvim` script, or a startup option of MacVim. Anyway, I couldn't find the solution. Any suggestion?
>
> Best, /nm
>
> P.S. My `mvim` script:
>
> #----------------------------------------------------------------------------
> #!/bin/sh
>
> if [ -z "$VIM_APP_DIR" ]
> then
> myDir="`dirname "$0"`"
> myAppDir="$myDir/../Applications"
> for i in ~/Applications ~/Applications/vim $myDir $myDir/vim $myAppDir $myAppDir/vim /Applications /Applications/vim /Applications/Utilities /Applications/Utilities/vim; do
> if [ -x "$i/MacVim.app" ]; then
> VIM_APP_DIR="$i"
> break
> fi
> done
> fi
> if [ -z "$VIM_APP_DIR" ]
> then
> echo "Sorry, cannot find MacVim.app.  Try setting the VIM_APP_DIR environment variable to the directory containing MacVim.app."
> exit 1
> fi
> binary="$VIM_APP_DIR/MacVim.app/Contents/MacOS/Vim"
>
> # Next, peek at the name used to invoke this script, and set options
> # accordingly.
>
> name="`basename "$0"`"
> gui=
> opts=
>
> # GUI mode, implies forking
> case "$name" in m*|g*|rm*|rg*) gui=true ;; esac
>
> # Restricted mode
> case "$name" in r*) opts="$opts -Z";; esac
>
> # vimdiff, view, and ex mode
> case "$name" in
> *vimdiff)
> opts="$opts -dO"
> ;;
> *view)
> opts="$opts -R"
> ;;
> *ex)
> opts="$opts -e"
> ;;
> esac
>
> # Last step:  fire up vim.
> # The program should fork by default when started in GUI mode, but it does
> # not; we work around this when this script is invoked as "gvim" or "rgview"
> # etc., but not when it is invoked as "vim -g".
> 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
> #----------------------------------------------------------------------------

--
--
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/groups/opt_out.