0

I have this in my '~/.vimrc' (among other things):

set guioptions += M
set guioptions -= m

to disable the menus in MacVim. I find that leaving out the '+=M' results in lots of keys being mapped (the menu hot keys etc.).

There is one facility provided by the system menu that I really would like: the ability to show all current MacVim "windows" (in the operating system sense, and not in the Vim sense of a "split"). For example, I could do something like this (perhaps in separate shells, at separate times):

$ mvim foo.txt
$ mvim bar.txt
$ mvim baz.txt

This will result in 3 separate MacVim "windows". With "set go=+M" not set, I can go to the "Windows" menu and see a these three instances listed and, optionally, select one of them.

Is there any way to do this without enabling the system menu, or at least the rest of it?

My motivation is this: after a while, I tend to end up with lots of different MacVim "windows" across multiple desktop spaces (I also tend to use a lot of desktop spaces). Sometimes I try to open, e.g., "foo.txt", only to get the notification that "foo.txt" is already open. Hunting down window in which it is open is a hassle. Yes, yes, I suppose I could change my entire way of dealing with this --- restricting myself to just one MacVim window, being disciplined about quitting files that I am not immediately working on etc. etc. But short of that, is there something else I could be doing?

I would also be happy if there was a command that I could issue either from the shell or from within Vim, that lists the windows and allowed me to activate one of my choice.

Edit

Turns out that MacVim has a ':macaction selectNextWindow:' command that at least allows me to cycle through the various instances:

nnoremap <silent> <M-`>   :macaction selectNextWindow:<CR>
nnoremap <silent> <D-`>   :macaction selectNextWindow:<CR>
nnoremap <silent> <M-S-`> :macaction selectPreviousWindow:<CR>
nnoremap <silent> <D-S-`> :macaction selectPreviousWindow:<CR>

I mapped both the command ('<D->') and meta ('<M->') because the former mapping only works with MacVim windows in the same desktop space. Weird. A partial solution in that I (eventually) find the window/instance I want, but at O(n) complexity. A window list would make it O(1).

Jeet
  • 38,594
  • 7
  • 49
  • 56

1 Answers1

0

It's generally possible to access menus from the command-line with a command like:

:amenu Edit

but adding M to 'guioptions' means that no menus are loaded whatsoever so :amenu is useless in your case.

Anyway, that window listing feature is provided by MacVim's Cocoa wrapper: it is part of the default functionalities any GUI application gets for free when created in XCode. MacVim doesn't appear to expose it to the Vim core, though, so you are kind of fucked:

  • the windows list is not available through :amenu,
  • set guioptions+=M gets rid of all menus, Vim-provided menus and Cocoa-provided menus.

There's another way to look at your problem: MacVim GUI windows are in fact separate Vim instances that all run as servers (see :help clientserver) and you can issue:

$ vim --serverlist

or:

:echo serverlist()

But I don't know of any high-level solution to manage separate servers and I have a feeling that it wouldn't be exactly trivial to come up with a solid solution.

Another way to look at your problem would be to selectively unmap all those undesired mappings without messing with the menus.

So yeah… my advice is to find another, more focused workflow.

If you use mvim often but don't want those menu-related mappings you might as well use mvim -v and work directly in your terminal which would almost certainly fix your mappings issue and your "same file opened in several instances" issue in one shot.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • Yes, I tried `serverlist`: it shows the instances available, but I cannot figure out a way to switch or select them. I figured out a way to cycle through the windows using the '`:macaction`' command (see my edited question above): not ideal, as I have to traverse through the the instances till I find the one I want, but I guess it is better than nothing. – Jeet Jul 06 '14 at 16:08