VIM Fireplace on Git Bash

VIM Fireplace - a vim plugin for Clojure development. Getting it working on Git Bash was not easy, but worth it.

Posted: Fri 24 Mar, 2017, 10:03

As a Java/Groovy developer using Eclipse, I will admit it has been a battle to move to Clojure. When moving from Java to Groovy, I was able to keep the same IDE but just change languages. When moving to Clojure, it has been necessary to move IDE and language at the same time - never a good idea. Clojure development does work in Eclipse (via CounterClockwise), but I had difficulty getting some basic things like "jump to definition" working and projects always showed errors even when they worked.

There are few options for developing Clojure - IntelliJ, Cursive, Emacs and VIM with the Fireplace plugin. Given these options, my instinct was to try and get VIM working with Fireplace, for a few reasons. I know vi, have used it for years and it my go-to editor of choice. Secondly, developing Clojure involves using an external REPL, so there is not the same need for a super-smart IDE. Lastly, I just like working in vi, it's so quick, clear and mouse-free.

The one argument against VIM Fireplace is that lack of a debugger. Having spoken to some other Clojure developers though, this may be wrong-headed of me. Clojure developers do not seem to need a debugger because it is to easy evaluate expressions on-the-fly in the REPL. I am going with this for now, and hoping I can survive without a debugger.

The Git Bash problem

There is one more complication - I work behind a corporate firewall on a Windows machine - so I have limited access to download all the zips and packages of choice. VIM's natural home is on Linux, so there are two choices for using it on Windows running on Windows. Either GVIM which is a graphical, window-ed wrapper around VIM or the Git Bash, a Windows terminal emulator, which is includes VIM 7.4. I like working at the command line so it was Git Bash for me - which is available to me on my internal work network.

However, getting VIM + Fireplace + Git Bash working took me a few days so I have noted down the main fixes here:

  1. Git Bash is a bit bizarre - but it works

    Git Bash is a Bash terminal, running on Windows, with some essential commands ported to Windows, that is provided as part of the Git. And vi is one of the essential ported commands (!). A rather tenuous way of getting a development tool - i.e. via ported package for a source control system - but it works, very well actually. It makes everything look like you are on Linux, but actually you are on Windows. When using Vundle to download a plugin for VIM, VIM does a git clone behind the scenes. Naturally, git thinks you are on Windows so will make sure your EOL characters are Windows-friendly. This means they are corrupt from the VIM point of view. It is therefore necessary to temporarily change turn off autocrlf in git before running :PluginInstall in VIM, and then revert it back after.

     git config --global core.autocrlf false

    will turn it off, and then

     git config --global core.autocrlf true

    will revert it back. With this trick in place, it is possible to add the VIM Fireplace plugin.

  2. Make sure you have Python 2.X installed and in your path

    In order to talk from the Fireplace plugin to the REPL, python is used. Specifically Python 2.X. Without this, you will receive errors like "Socket closed" within the REPL when you run a command within VIM (like jump to definition).

  3. Windows/Linux path confusions "Couldn't find source for "

    Jumping to a definition is the absolute minimum feature required to turn an editor into an IDE. Without this, there was no way I could develop Clojure using VIM. However, once I had everything in place, it was still not working. When I did [ Ctrl d over a function, it would pause and say "Couldn't find source for ". After a few days learning the basics of VIMScript, I was able to fix this by changing the classpath return by the REPL to VIM. When the REPL tells VIM where a symbol is, which is a filename and line number, VIM then finds that file on the classpath provided by the REPL. Unfortunately the REPL thinks it is running on Windows (which it is), and VIM thinks it is on Linux, so it never finds the files in the locations expected.

    To fix this, I hacked the s:register_connection in fireplace.vim to update the paths to be Linux-ified. I may have to add this to another location in the code, but this is working perfectly now for my base use case. I can now jump around the code... yay!

The code:

    " Update for vim on Git bash
        let paths = s:repls[0]["connection"]["_path"]
        let i = 0
        for path in paths
          let path = substitute(path, "^", "\/", "")
          let path = substitute(path, "\\", "\/", "g")
          let path = substitute(path, "C:", "C", "")
          let paths[i] = path
          let i += 1
        let s:repls[0]["connection"]["_path"] = paths

        let s:repl_paths[a:1] = s:repls[0]


  • Must have python 2.X in your path (all VIM/Repl chat fails without this)
  • Java 1.8 helps
  • Leiningen latest

Some useful links:

VIM Scripting and Debugging

Useful commands:

  • :Eval *e - useful to show the actual error, better than cryptic Vim(return):E730: using List as a String