How do you run coffeescript from Vim?

I am relatively new to Vim (from TextMate) and used the kchmck Vim coffeescript plugin . This is great, but I missed the cmd-R feature in TextMate to run coffeescript fragments using the jashkenas TextMate package . Anyone have any tips on setting this up with Vim?

+7
source share
5 answers

I have no experience with CoffeeScript, but from your second link, I understand that your document has been passed to the coffee command.

Have you tried :!coffe % ?

  • :! to run an external command,
  • coffee external team,
  • % , extended by Vim at runtime, represents the current file.

EDIT

Add this to your .vimrc :

 nnoremap <Dr> :!coffee %<CR> 
  • nnoremap mapping only works in normal mode,
  • <Dr> - Cmd r , after which there is a sequence of commands,
  • :!coffee % team,
  • <CR> Enter
+13
source

If you want to use Cmd r to run in both command line and edit mode, add this to your ~ / .vimrc file:

 inoremap <Dr> <ESC>:!coffee %<CR> nnoremap <Dr> :!coffee %<CR> 
  • inoremap is called in edit mode
  • nnoremap will be invoked in command mode
+3
source

For those who are looking at it now, vim-coffee-script now supports the CoffeeRun command. (I assume this was not at the time this question was originally asked.)

The CoffeeRun command compiles the current file or CoffeeRun and runs the resulting JavaScript. The output is displayed at the bottom of the screen.

CoffeeRun: run Some CoffeeScript

+2
source

It does not look like this plugin is currently being offered. Perhaps you should write a function request ?

Alternatively, you can use the Vim plugin to compile and observe compiled JS with something like node-supervisor , run it every time the JS changes.

0
source

The ability to run CoffeeScript inside vim is very convenient. To configure this, first install CoffeeScript support for vim from kchmck (I use pathogen for my installation). Then just put the following in the vimrc file:

 imap <silent> <Leader>ss :w^M:!clear; mocha %^M map <silent> <Leader>ss :w^M:!clear; mocha %^M 

and you can enter your leader key + zz to run the current CoffeeScript file. Note that this will automatically save the file before running mocha tests.

0
source

All Articles