XCode – Open file in current tab in external editor (MacVim)

I wanted to open the current file from XCode 5 in MacVim similarly as I do in IntelliJ. After some research I found following solution that works for me. If Assistant editor is opened, the file from the Standard Editor (on the left side) is opened regardless which editor is active.

First raised as a StackOverflow question.

Update: In case you were wondering how to start MacVim from XCode, you should maybe try XVim instead. It brings Vim mode right into XCode.