This project adds CoffeeScript support to the vim editor. It handles syntax, indenting, and compiling.
Installing the typical way takes less time, but leaves plugin files scattered.
Download the latest zipball off this plugin's vim.org page.
Extract the archive into
unzip -od ~/.vim vim-coffee-script-HASH.zip
These steps are also used to update the plugin.
Since this plugin uses "rolling releases" based on git commits, using pathogen and git is the preferred way to install. It takes more steps, but ends up cleaner and easier to keep up-to-date.
Install tpope's pathogen into
~/.vim/autoload/and add this line to your
Be aware that it must be added before any
filetype plugin indent onlines according to the install page:
Note that you need to invoke the pathogen functions before invoking "filetype plugin indent on" if you want it to load ftdetect files. On Debian (and probably other distros), the system vimrc does this early on, so you actually need to "filetype off" before "filetype plugin indent on" to force reloading.
To get the all the features of this plugin, be sure you do have a
filetype plugin indent online.
Create, and change into, the
$ mkdir -p ~/.vim/bundle $ cd ~/.vim/bundle
Make a clone of the
$ git clone https://github.com/kchmck/vim-coffee-script.git
Change into the
$ cd ~/.vim/bundle/vim-coffee-script
Pull in the latest changes:
$ git pull
Compiling the Current File and Autocompiling
CoffeeMake command compiles the current file and parses any errors.
CoffeeMake shows all compiler output and jumps to the first line
reported as an error by
Compiler output can be hidden with
Line-jumping can be turned off by adding a bang:
Options given to
CoffeeMake are passed along to
To get autocompiling when a file is written (formerly
autocmd like this to your
autocmd BufWritePost *.coffee silent CoffeeMake!
All of the customizations above can be used, too. This one compiles silently
-b option, but shows any errors:
autocmd BufWritePost *.coffee silent CoffeeMake! -b | cwindow | redraw!
redraw! command is needed to fix a redrawing quirk in terminal vim, but
can removed for gVim.
Default compiler options
CoffeeMake command passes any options in the
variable along to the compiler. This can be used to set default options:
let coffee_make_options = "-n"
Compiling a CoffeeScript Snippet
CoffeeCompile command shows how the current file or a snippet of
CoffeeCompile without a
range compiles the whole file:
CoffeeCompile with a range, like in visual mode, compiles the selected
snippet of CoffeeScript:
This scratch buffer can be quickly closed by hitting the
Running some CoffeeScript
CoffeeRun command compiles the current file or selected snippet and runs
These customizations can be enabled by adding lines to your
Use two-space indentation in *.coffee files
coffee compiler requires space indentation by default; vim inserts tabs.
To use standard two-space indents in coffeescript files, add the following line:
au BufNewFile,BufReadPost *.coffee setlocal shiftwidth=2 softtabstop=2
Fold by indentation
Folding is automatically setup as indent-based:
It's disabled by default, but can be enabled with:
let coffee_folding = 1
Otherwise, it can be quickly toggled per-file by hitting
Disable trailing whitespace error
Trailing whitespace is highlighted as an error by default. This can be disabled with:
let coffee_no_trailing_space_error = 1
Disable trailing semicolon error
let coffee_no_trailing_semicolon_error = 1
Disable reserved words error
Reserved words like
var are highlighted as an error in contexts
disallowed by CoffeeScript. This can be disabled with:
let coffee_no_reserved_words_error = 1