This project adds CoffeeScript support to the vim editor. Currently, it supports almost all of CoffeeScript's syntax and indentation style.
-
Install tpope's pathogen into
~/.vim/autoload/
and add the following line to your~/.vimrc
:call pathogen#runtime_append_all_bundles()
Be aware that it must be added before any
filetype plugin indent on
lines 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.
-
Create, and change into, the
~/.vim/bundle/
directory:$ mkdir -p ~/.vim/bundle $ cd ~/.vim/bundle
-
Make a clone of the
vim-coffee-script
repository:$ git clone git://github.com/kchmck/vim-coffee-script.git [...] $ ls vim-coffee-script/
That's it. Pathogen should handle the rest. Opening a file with a .coffee
extension or a Cakefile
will load everything.
-
Change into the
~/.vim/bundle/vim-coffee-script/
directory:$ cd ~/.vim/bundle/vim-coffee-script
-
Pull in the latest changes:
$ git pull
Everything will then be brought up to date.
The CoffeeCompile
command can be used to peek at how the current file or a
snippet of CoffeeScript would be compiled to JavaScript. Calling CoffeeCompile
without a range compiles the entire file:
and shows an output like:
Calling CoffeeCompile
with a range, like in visual mode, compiles the selected
snippet of CoffeeScript:
and shows an output like:
The command can also be mapped to a visual mode key for convenience:
vmap KEY :CoffeeCompile<CR>
These customizations can be enabled or disabled by adding the relevant let
statement to your ~/.vimrc
.
To compile the current file at each save, set:
let coffee_compile_on_save = 1
This just calls coffee -c
on the file, so make sure coffee
is in your
$PATH
. Currently, no compiler output or errors are shown.
Trailing whitespace is highlighted as an error by default. This can be disabled with:
let coffee_no_trailing_space_error = 1
Trailing semicolons are also considered an error. This can be disabled with:
let coffee_no_trailing_semicolon_error = 1
Reserved words such as function
and var
are highlighted an error in contexts
disallowed by CoffeeScript. This can be disabled with:
let coffee_no_reserved_words_error = 1