Macvim App



One of the easiest way to install MacVim is via Homebrew. If you do not have Homebrew installed I highly recommend you install it. Just go to this site brew.sh and follow the install instructions there. Once you have home brew installed you should be able to run the.

  1. App name: macvim; App description: A GUI for vim made for OS X; App website: Not Available; Install the App. Press Command+Space and type Terminal and press enter/return key.
  2. MacVim installer only copy MacVim.app into Application directory, but it does not add the path into user's.profile file. To enable command line to use mvim command.
  3. # MacVim.app application bundle. If you make links to this script as view, If you make links to this script as view, # gvim, etc., then it will peek at the name used to call it and set options.

Even though I use PyCharm, I still drop into Vim occasionally to edit configuration files. This was an annoying process until today, when I discovered that PyCharm and other Intellij editors can open the current file in an external tool. This works with both GUI and console-based applications, and its most trivial use case seems to be opening the current file in an external editor.

So, how does it work? Easy — this should only take a minute or so! Instructions are geared toward OS X users, but should be clear to users on other operating systems.

Step 1: Set up an external tools entry for your editor

  • Open PyCharm -> Preferences
  • Click on or search for “External Tools”
  • Click the “+” button
  • Give your editor a name, like MacVim
  • Check “Synchronize files after execution” to sync edits made between the editors while the file is open in both
  • Uncheck “Open console” if the editor is a GUI application
  • Set the program path — for GUI OS X applications, this is the application bundle, e.g. /Applications/MacVim.app
  • For “Parameters” enter “$FilePath$”, an Intellij macro that will automatically send the absolute path of the current file to the external editor
  • For “Working directory” enter “$ProjectFileDir$”, an Intellij macro that will automatically set the working directory to the directory containing your Intellij project file; this is my preference because in PyCharm the project file directory is usually the directory you opened the first time you opened your code in PyCharm, and for me, that is my git checkout (see “Insert macro” for other directories you can use)
  • Click OK

Step 2: Assign a keymap to the editor

One of my favorite things about this feature is that PyCharm lets you assign a key binding to each tool, so now that you have a “MacVim” tool in the menu tree, you can assign it a key binding.

  • Open PyCharm -> Preferences
  • Click on or search for “Keymap”
  • Select your keymap
  • Search for “MacVim” or whatever editor name you gave the external tool
  • Double click on it and then click “Add keyboard shortcut”
  • Set whatever shortcut you like; Control+Shift+E worked for me
  • Click OK

Step 3: Try it out

All right! Now the moment of truth. Open a file in PyCharm and use your keybinding, or navigate to the Tools -> Editors -> MacVim (for example) menu item. This should open MacVim with the file you chose, and better yet, the working directory will be set to the project root (at least in my setup, where all my PyCharm project files live in my project root directories).

Macvim App Reviews

Hope this was helpful! It certainly made my day. (Now if only I could change the detected file type of an open file within PyCharm, like I can with every other text editor on the planet.)

Get my newsletter.

Mac Vim Map Command To Key

You'll get an occasional email when I'm excited enough about a technology to write about it.

Macvim

Macvim Plugins

Macvim plugins

For the past several weeks I have been using MacVim as my primary editor for Ruby coding. My workflow has been to edit some code, Command-Tab over to a Terminal window and run a test by either typing the command, or using the up-arrow to run the same test I had already typed in.

This worked pretty well, but it was annoying needing to type in the full path to the test file when running a new test. And I would often Command-Tab just once thinking this would take me back to a Terminal window, but end up looking at a browser forgetting that I had been reading some documentation in between test runs.

I played around with some techniques for running the test file “inside” of MacVim, but did not like how they would lock up my editor, or added new buffer splits to show the output.

To improve my workflow I put together a few Vim functions for running a test file in a specific Terminal or iTerm tab using an AppleScript helper script (executed with the osascript command line tool). When I start working on a project I set a global variable specifying the TTY name of the Terminal tab I want to run the test in. Running the tty command in Terminal or iTerm will print out the value that needs to be set. I use the following mapping as a shortcut for setting the global variable, including a hardcoded default value.

Appstore

Three functions are provided in the following Vimscript. One runs the entire file, one runs the file at a specific line, and the last re-runs a previously run file.

The following AppleScript looks pretty awful, but it seems to work and I just can’t muster up the motivation to spend the time learning the language well enough to make it any better. The Vim functions above expect this script to be reside in ~/.vim/tools/run_command.applescript. It looks through all of the Terminal.app and iTerm.app tabs trying to find one that matches a given TTY name.

Macvim App Download

If there is interest I am thinking about packaging this up as a Vim plugin, but for now you can just download the files and fit them into your Vim configuration however you see fit.

Macvim App Download

Mac vim profile

One final note: I tried this out in the native Vim that comes with Mac OS X and it seems to work, but I haven’t really tested it much in anything other than the latest MacVim (7.3).