Friday, May 7, 2010

Easy Clojure developement with Vim

Starting with Vim or Clojure can be difficult. Starting with both at the same time is not recommended. But it can get difficult for someone who knows both. Following is a simple way how I do my development:
I edit clojure scripts in Vim. I found putting following lines in .vimrc very helpful:
set showmatch 
map <F5> <Esc>:!clj '%:p'<CR>
The first one is for highlighting matching (,{ and [. The second one is for executing the currently edited file.  Please note that !clj '%:p' just invokes shell command clj with the fully qualified path of the current buffer you are editing and it is mapped to the F5 function key.  If you are using MacVim, make sure that you put following lines in your .vimrc file:
let $PATH="path/to/clojure/home/bin:".$PATH
I also use a vim plug in called “AutoClose” (here: http://www.vim.org/scripts/script.php?script_id=1849) that will automatically close parenthesis, brackets and curly braces. You can also do yourself a favor by installing a plug in called “VimClojure” (here: http://www.vim.org/scripts/script.php?script_id=2501). I only use syntax highlighting feature and do not run interactive REPL with it(I do not recommended using nailgun server). The above is just enough to do small scale development. However, for involved development, there is dependency and class path hurdles to overcome. It is even worse for someone who is new to Java World from other dialects of LISP.  To ease the pain, I created a project called Clojurew (here: http://bitbucket.org/kasim/clojurew/src) that will do automatic class path resolution. Any jar dependency will be resolved by just coping the jar to the lib folder of Clojurew. If you want to include your own script to the class path,  you can even create a soft link to your script within the lib directory and it will be included in the class path as well. Here is how you can do this:
 ln  -s path/to/your/script linkname
After this, you can use any function in your script that is defined in other files.  Happy Vimming and Clojuring!
I hope someone find this helpful.

No comments:

Post a Comment