Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you run coffeescript from Vim?

I'm relatively new to Vim (from TextMate), and have been using kchmck's Vim coffeescript plugin. It's great, but I miss being able to cmd-R in TextMate to run snippets of coffeescript using jashkenas's TextMate bundle. Anyone have any tips on setting this up with Vim?

like image 259
Dylan Avatar asked May 07 '11 16:05

Dylan


3 Answers

I have no experience with CoffeeScript but from your second link I gather that your document is given to a coffee command.

Did you try :!coffe %?

  • :! to run an external command,
  • coffee the external command,
  • % expanded by Vim at the time of execution, represents the current file.

EDIT

Add this to your .vimrc:

nnoremap <D-r> :!coffee %<CR>
  • nnoremap the mapping works in normal mode only,
  • <D-r> is Cmdr after that comes the sequence of commands,
  • :!coffee % the command,
  • <CR> Enter
like image 126
romainl Avatar answered Oct 24 '22 13:10

romainl


If you'd like to be able to use Cmdr to run in both command mode and edit mode, add this to your ~/.vimrc:

inoremap <D-r> <ESC>:!coffee %<CR>
nnoremap <D-r> :!coffee %<CR>
  • inoremap will be called in edit mode
  • nnoremap will be called in command mode
like image 30
rgbrgb Avatar answered Oct 24 '22 15:10

rgbrgb


For anybody looking at this now, vim-coffee-script now supports the CoffeeRun command. (I assume it didn't at the time this question was originally asked.)

The CoffeeRun command compiles the current file or selected snippet and runs the resulting JavaScript. Output is shown at the bottom of the screen.

CoffeeRun: Run some CoffeeScript

like image 2
kmikael Avatar answered Oct 24 '22 15:10

kmikael