Programming Scheme(Racket) with VIM - How to get started
Asked Answered
F

3

31

recently, I started programming Racket (formerly Scheme) in DrRacket. I quite fast I began to miss all the features of VIM in DrRacket, so I would like to use VIM for my scheme(racket) programming.

I know that Emacs might be the best choice for intense lisp programming, but all I want is write a scheme(racket) file check syntax and then run it.

Unfortunately, I could not figure out, how to invoke "racket" in the commandline on a file to get it doing the same as DrRacket.

I am running Ubuntu 10.10 Maverick Meerkat, VIM 7.3 and I downloaded and installed Racket from the official website.

Help to get started would be very appreciated.

Falbala answered 18/3, 2011 at 13:56 Comment(0)
P
24

If you just want to load a file into Racket on the command-line and run it, I think that this should work:

$ racket -f file.scm -i

The -i option would leave you at the REPL to test your code in file.scm.

However, you might want to take a look at this blog post:

http://technotales.wordpress.com/2007/10/03/like-slime-for-vim/

You can set up a GNU screen session running the command-line Racket, and send s-expressions to it from Vim. There's a link to a bit of Vimscript which will make this automatic. I used this for a while with mit-scheme, and it was reasonably effective. It's not quite the as powerful as SLIME or DrRacket though. I just tested the steps described on OS X and it works with the command-line racket, it should work on Ubuntu, that's what I was using when I first used this method.

You might also want to take a look at this:

http://evalwhen.com/scmindent/index.html

... which has some information on better indentation in Vim for Lisp and Scheme code.

I eventually switched to Emacs, but don't let the Vim haters get you down. Paul Graham supposedly uses vi and he's gotta be one of the top 5 most prominent Lisp programmers.

http://paul.graham.usesthis.com/

Pouch answered 18/3, 2011 at 14:13 Comment(4)
Thanks for the tips, but running from within vim with the racket -f file -i command gives me: reference to undefined identifier: check-expect Is check-expect only DrRacket?Falbala
ok thanks i figured out to add #lang scheme (require htdp/testing) (check-expect 1 2) (generate-report)Falbala
Sorry I hadn't thought about that #lang specifier, I usually use Racket in R5RS mode. Glad you got it to work though!Pouch
The evalwhen link shows a Japanese spam page.Why
L
17

Several add-ons are available to make coding in Racket more satisfying with Vim.

  • Vim’s lisp mode (set lisp) -- improves some basics for indenting and w/e/b word-hopping.
  • vim-racket -- sizable set of vim-syntax recognition for functions and syntax
  • syntastic -- identify errors upon save (vim-racket sets makeprg for this to work)
  • Rainbow Parentheses -- set your own paren colors for maximal contrast!
  • vim-slime -- use with Tmux to connect Vim to a Racket REPL
  • surround -- wrap forms and elements in parens
  • vim-sexp for normal people
  • Molokai color scheme -- high contrast
  • VROD* -- K-based Vim documenation, and auto-completion of Racket functions
  • REPTL* -- very simple continuous rackunit test runner

I prefer slime over slimv for its simplicity.

If you are using Vundle, here is a way to install most of the add-ons mentioned:

Plugin 'tpope/vim-surround.git'
Plugin 'kien/rainbow_parentheses.vim'
Plugin 'scrooloose/syntastic.git'
Plugin 'MicahElliott/vrod'
Plugin 'guns/vim-sexp'
Plugin 'tpope/vim-sexp-mappings-for-regular-people'
Plugin 'wlangstroth/vim-racket'
Plugin 'tomasr/molokai.git'

Put those into your ~/.vimrc, and then invoke to install:

% vim +PluginInstall +qall

Here is a screenshot showing off most of these:

enter image description here

(* disclosure: I wrote VROD and REPTL, and they are immature)

Also, here is a related blog post describing a Vim/SICP setup.

Legra answered 13/8, 2015 at 22:57 Comment(1)
Paredit is also useful for structured editing and making sure that there are no unbalanced parentheses. Slimv includes paredit; this is the standalone version.Why
C
2

As of about a week ago, SLIMV (SLIME for Vim) supports Racket. SLIMV is generally regarded as the most mature Lisp environment for Vim at the moment.

Competence answered 2/1, 2014 at 20:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.