macvim-dev / macvim

Vim - the text editor - for macOS
https://macvim.org
Vim License
7.47k stars 680 forks source link

"open -a MacVim.app" does not focus an existing instance #1275

Closed airblade closed 1 year ago

airblade commented 1 year ago

Steps to reproduce

  1. On the command line, open a file in MacVim: mvim foo.txt.
  2. Focus a different application, e.g. Safari.
  3. On the command line, try to focus MacVim: open -a MacVim.app.

Expected behaviour

Expected outcome: the MacVim instance from step 1 is focused.

Actual outcome: a new MacVim instance is launched.

I use Karabiner to map my function keys to launch/focus different applications. Each function keys executes a shell command like, open -a Safari.app. Before I installed MacVim 9 this worked for MacVim for many years. However with MacVim 9 it keeps launching new instances, regardless of what I set the preference "Open untitled window" to.

Version of Vim and architecture

9.0.65

Environment

MacOS 12.5.1, iTerm 2, xterm-256color, GNU bash 5.0.9(1)-release.

How MacVim was installed

Downloaded from GitHub's releases.

Logs and stack traces

No response

Vim configuration where issue is reproducable

No response

Issue has been tested with given configuration

Issue has been tested with no configuration

Other conditions

eirnym commented 1 year ago

Hi @airblade, thank you for an issue

I've just tried and can't reproduce the issue. I have no Karabiner on my computer as the most things I want to configure I can do with macOS settings. I have MacVim installed via GitHub releases.

Could you please, describe why do you need to install both vim and MacVim using HomeBrew?

Please note, that MacVim provides it's own modified vim to make integration magic work well and installation of both vim and MacVim can break this magic. In other words, MacVim is not a graphical terminal emulator and few keybindings built around Vim. In other words packages are conflicting between each other.

airblade commented 1 year ago

Could you please, describe why do you need to install both vim and MacVim using HomeBrew?

I used Homebrew in the past to install the HEAD version of MacVim. More recently I have just downloaded releases instead.

Your question prompted me to tidy up and remove the MacVim (and Vim) installed via Homebrew.

I also took a look at the mvim script. I've had a version of this in my ~/bin directory for 12 years. I just read :help macvim-start and it (now) recommends adding /Applications/MacVim.app/Contents/bin to my path rather than symlinking it or copying it.

Anyway, after all that, open -a MacVim.app is working again.

Thank you for your help!

eirnym commented 1 year ago

You're welcome

ychin commented 1 year ago

Yeah macOS gets confused if you have multiple versions of the app installed, especially since you are just opening "MacVim.app" without providing a path. It just grabs one of the two installed versions of MacVim for you.

I have to deal with this annoying issue a lot locally since I frequently have like at least 4-5 MacVim.app sitting on my local computer for development and testing (the officially installed version, the local Debug/Release builds, previous builds for comparisons, and so on), so I usually just provide the full path when I use open, but for you just having one version of MacVim installed is definitely the way to go.

As an aside, responding to @eirnym's comments: It is ok to have both official Vim and MacVim installed, but probably unnecessary. The main issue is mostly configuring your PATH to make sure vim is mapped to the correct one so you can invoke it in the terminal, but if you say want vim to be mapped to regular terminal Vim (maybe installed via Homebrew to get the latest version), but mvim to map to MacVim (say installed via binary releases), that's fine, and nothing will break. Just confusing for yourself as you will be juggling between two versions of Vim.

airblade commented 1 year ago

Thanks @ychin.

In the past I was able to install the HEAD version of MacVim via Homebrew, along with having a release version from here on GitHub, but I think when I tried to update the HEAD version to get v9 before it was available as a release, I must have messed something up.

These days my Homebrew updates usually end up failing, due to some random Python 2 vs 3 conflict in a dependency of a dependency I've never heard of, and leave my system in a suboptimal state ¯\_(ツ)_/¯

Thanks again!

eirnym commented 1 year ago

Thank you @ychin, there were previously issues with installation of both vim and MacVim. Glad to hear, that things were changed

eirnym commented 1 year ago

@airblade I have an aliases to run both MacVim GUI and terminal version without actually using mvim script

I had enough issues between mvim to run GUI, mvim to set as an editor (e.g. for git) and to cover various environments including running MacVim as a root after sudo su -. Thus I use Vim and MacVim binaries directly.