Open the current file in Vim, Emacs or Sublime Text from PyCharm

I spend a lot of time in Pycharm because it can do pretty much everything I need during a full day of development. However, sometimes I still drop into Vim, especially when I need to edit configuration files.

This was an annoying process until today, when I discovered that PyCharm and other Intellij editors can easily send the current file to an external tool. This feature is powerful and generic, suitable for both GUI and console-based applications, but its most trivial use case seems to be opening a file in an external editor.

So, how does it work? Easy — this should 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

Adding an external tool in PyCharm

Setting the program path for an external tool in PyCharm

Choosing MacVim as an external tool in PyCharm

Clicking on insert macro for the parameters setting of an external tool in PyCharm

Selecting the FilePath macro for an external tool in PyCharm

Clicking to insert a macro for the working directory setting of an external tool in PyCharm

Selecting the ProjectFileDir macro for an external tool in PyCharm

Viewing a completed MacVim external tool in PyCharm

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

Adding a key binding for a MacVim external tool in PyCharm

Adding a key binding for a MacVim external tool in PyCharm (2)

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).

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.)

Clicking on a new MacVim external tool menu item

Viewing a file opened from PyCharm in MacVim

Video of my DjangoCon talk “The evolution of a RESTful Django backend”

The video of my first ever conference talk is now available on YouTube. Check it out here or watch it below. It could have been better, but least now my daughter will always be able to find a video of her dad looking foolish on the internet. The talk was a look at different web […]

Continue reading...

An Epic Review of PyCharm 3 from a Vim User’s Perspective

Code Completion

This review is for the Professional Edition of PyCharm 3. It includes screenshots and sound-free video demos of PyCharm features. I will try to cut straight to the point while offering some tips from my experience. My perspective is that of a professional software developer who has used Vim, Emacs, Sublime Text, PyDev and others. […]

Continue reading...

Porting a Geographic Nearest-Neighbor Python Web Service to Go

I wrote a blog post recently at work that described my experience porting a geographic nearest-neighbor web service from Python to Go. You can read it on the Safari Flow blog. The post covers setting up a dev environment for Go, finding replacement third-party libraries, writing tests, performance profiling and deployment. If you'd rather read […]

Continue reading...

Four Things I Learned about Software Engineering from Programming MUDs as a Teenager

In job interviews I try to casually drop that I learned how to program as a teenager writing C code for MUDs1. My intent is to open a fun discussion into why this was awesome. Programming for MUDs taught me the fundamentals of the craft, so I could probably ramble about it for an hour. […]

Continue reading...

On Starting a Daily Meditation Practice

The single thing that improved my daily life the most in 2013 was starting a daily meditation practice. Specifically, Buddhist meditation based on techniques from the Ānāpānasati Sutta and Satipaṭṭhāna Sutta. In this post I will share why I started, how I did it and some pleasant results. Suffering As I suspect many new parents […]

Continue reading...

Reading List for an Apprentice Web Developer

Here are a few books that I found useful when I was starting out as a web developer. I originally wrote this list for a friend who is wrapping up his Computer Science degree, so the emphasis is on practical rather than academic knowledge. Craft These books touch on a lot of non-technical areas of […]

Continue reading...

Wrap Comments and Text to Column Width in IntelliJ Editors

One of the small annoyances I found after switching to PyCharm recently was that while the editor will reformat code to the chosen column width, it won’t wrap plaintext or comments. Annoying, for Vim and Emacs users! I corrected this by writing my first IntelliJ plugin: Wrap to Column, which is a port of a […]

Continue reading...

Build an In-Memory Proximity Search Web Service with Python, SciPy and Heroku

In this post I’m going to look at a concrete example of building an in-memory proximity (aka, nearest neighbor) search web service using Python, SciPy and Heroku. Later we can speculate on use cases for this approach as opposed to a geo-aware database. Define Our Terms So, let’s define our terms: In-memory: The web service […]

Continue reading...

Revisiting Umberto Eco’s Future of the Book

In 2003 Umberto Eco gave a talk at the opening of the Bibliotheca Alexandrina titled, “Vegetal and mineral memory: The future of books” that is interesting to read again now, nine years later. His goal in the talk was to break apart the fear people had about “the future of books.” He addressed this fear […]

Continue reading...