1

I would like to use Snap (free) to assign a shortcut for Vim on Mac (installed as macvim through brew on command line). However, Snap only works when the application is literally "found as an application". Here's the window that Snap opens to find an "application"

Window of Snap trying to find an application

Is there a way to list the Vim (accessible through my Terminal as mvim) to be an application? Or, is there a way to call Vim with a keyboard shortcut, say Command+I?

0

To launch MacVim from a shortcut.

Launch Automator and go to File > New and select « Services »

Select « no input » in the « Service receives » list.

In the search box at the upper right, search after « Run AppleScript ». Double click on it and enter this script:

on run {input}
    set cmd to "vim"
    tell application "System Events" to set terminalIsRunning to exists application process "Terminal"
    tell application "Terminal"
        activate
        if terminalIsRunning is true then
            do script with command cmd
        else
            do script with command cmd in window 1
        end if
    end tell
end run

Save your automator script.

Go in the « Keyboard shortcut pane » in System preferences. Select service part. Go to your new MacVim automator script and assign your Command+I shortcut.

6
  • Hi @Redbug, here is the thing: Vim does not show up in the list of "application". I followed your suggestion up till the "launch application" step, however, from the list I got from launch application, I did not find any of "macvim, vim or mvim". Any suggestion on this? – llinfeng Mar 17 '16 at 15:43
  • Try "launch a shell script" in place of "launch application" and put the full path of your mvim application – RedBug Mar 17 '16 at 15:51
  • thank you for the timely update. I was able to find an "Action" called Run Shell Script, but feeding in vim ends up with a infinite loop (hitting run and the script keeps running); and feeding in mvim, which used to work on the terminal, was not recognized by the shell. \n In the list of available shells, I did not find an option for terminal. Should I install vim again for these different shells? – llinfeng Mar 17 '16 at 16:15
  • Ok.. My answer was modified with a solution that works with vim – RedBug Mar 18 '16 at 7:13
  • Hi @Redbug, your code does the job of passing the string "vim" to the Terminal and have got it executed. However, there are two ripples: 1. that the Terminal only got used once, every new "call of the automator script" shall live me with a fresh new Terminal instance; 2. that upon quitting the MacVim session (I changed the string from "vim" to "mvim"), the Terminal is still there; Thank you! – llinfeng Mar 19 '16 at 1:25
3

Background: It suddenly came to me that Mac is not only a programming machine, but rather a graphical sandbox whose operation is supposed to be intuitive. (This is day 2 of my attempt to use a Mac, as a long-time Windows user.)

Solution is simple:

  • Step 1: hold left-click on the (Mac)Vim symbol, and got to Option and then Show in Finder; this will bring us to where the executable file named as MacVim is located;

  • Step 2: Create an "alias" for the MacVim-executable. This essentially creates a shortcut that opens a MacVim instance;

  • Step 3: DRAG the "short cut" to the Application folder, found as the left-panel of the Finder.

Done.

PS: a failed attempt was to Duplicate the executable file, and drag it to the Application "folder" at the left panel of the finder; this ends up with essentially having two "installations" of Vim, of which will bring up two Vim icon if we open these two installations graphically. In short, alias and DRAGing helps!

PPS: Many thanks to RedBug, for this helpful lesson on Automator. In return, I will select his answer as the programmable solution, yet keep my personal solution here, as a backup. (As of Fri Mar 18, 2016, 22:31, I am still looking forward to a modification of the AppleScript that will terminate the Terminal once having opened it to execute "mvim" command.)

1

Had the same problem (MacVim did not appear in the Applications directory). Tried what was suggested above but did not manage to make it work. I chased the MacVim.app file until I found it (in my system) in /usr/local/Cellar/macvim/8.1-151

I duplicated the MacVim.app file, and put the copy in the Applications directory.

I now have 2 MacVims that work in my environment... but it is better than not being able to open some files with MacVim because it did not show up in the Applications directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.