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.

on run {input, parameters}

    set current_document_path to ""

    tell application "Xcode"
        set last_word_in_main_window to (word -1 of (get name of window 1))
        if (last_word_in_main_window is "Edited") then
            display notification "Please save the current document and try again"
            -- eventually we could automatically save the document when this becomes annoying
        else
            set current_document to document 1 whose name ends with last_word_in_main_window
            set current_document_path to path of current_document
        end if
    end tell

    tell application "MacVim"
        if (current_document_path is not "") then
            activate
            open current_document_path
        end if
    end tell

    return input
end run

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.

Starting Vim (gVim) from IntelliJ

Ever wanted to use Vim editing features while inside IntelliJ IDEA? Here is how to do it… You can even jump to the very same line you are on in IntelliJ.

Go to Settings > External Tools, add a new tool and use something similar:

Program: c:\Program Files (x86)\Vim\vim71\gvim.exe
Parameters: "+call cursor($LineNumber$,$ColumnNumber$)" "$FilePath$"
Working directory: $FileDir$

Update: IdeaVim – Vim commands right in the IDE

Additionally I finally tried the IdeaVim plugin for IntelliJ and my experience so far is pretty good. The need to start gVim externally almost disappeared.

Update: Open file in IntelliJ from gVim (Windows)

Save file + Open current file on the same line in IntelliJ + Close file in VIM

map! <F3> <Esc>:update<CR>:silent exe "!openIntelliJ.bat c: --line " . line(".") . " %:p"<CR>:q<CR>

  • :map! command creates a key map that works in insert and command-line mode.
  • :update is similar to ":w" or ":write", but only writes when the buffer has been modified.
  • silent prevents Hit enter cmd window.
  • line(".") returns current line number (dot is for the current)
  • %:p returns full file path of the current file
  • IntelliJ commmand line uses following syntax: [IntelliJ Path] [path1 = path to the project that contains the desired file] --line[number] [path to the file to be opened]

Here is my openIntelliJ.bat – one of the advantages is that I have just one place to change when I upgrade to a newer version (giving the exe to path variable would an option too):

start "" "c:\Program Files (x86)\JetBrains\IntelliJ IDEA 12.1.6\bin\idea.exe" %1 %2 %3 %4

The second attribute for Windows “start” command is title, I don’t need it, so I supply empty string.

References: