Category: coffeescript

  • Manipulating Coffeescript With Vim, Part 2: Wrapping and Unwrapping [coffeescript, vim]

    In coffeescript, particularly when you’re dealing with nodejs, code is often wrapped with lots and lots of callbacks. Since the indentation of the wrapping function calls varies, it’s not very easy to move them around, delete them, or add new ones, because you need to adjust the indentation of the blocks of code they contain.

    In my previous post, I defined two mappings to operate on blocks of code. In this one, I’ll define two that deal with the wrapping callbacks.

  • Manipulating Coffeescript With Vim, Part 1: Text Objects [coffeescript, vim]

    I recently started to write a lot of coffeescript at work, so I bumped into an issue that I’ve been avoiding for some time: manipulating indent-based languages. Theoretically, it should be easier (no “ends” or closing braces, right?), but I have a lot of tools to move code around, wrap it in blocks, or view it nicely, that just don’t work with semantic indentation. So, I had to experiment to come up with some vimscript to make it more comfortable. It’s all a work in progress, but it’s been rather useful for me so far.

    Originally, I intended to write a single post, but I started off rather verbosely, so I decided to make it a series instead and explain the code in more detail along the way. To begin with, I’ll describe the process of writing two simple text objects that might be useful in day-to-day coffeescript development.

    If you’re unfamiliar with text objects in Vim, you could get a good explanation from the help files with :help text-objects. Another nice introduction is Chapter 15 from “Learn Vimscript the Hard Way” by Steve Losh. It’s rather short, so I recommend you skip through it in any case.

  • Generating a Preview of a Coffeescript File in Vim [coffeescript, vim]

    I started writing a bit of coffeescript recently. One of its benefits is that the javascript it generates is fairly readable, which really helps in the learning process. To make it easier to see it, I whipped up some vimscript to open up a split window with the generated javascript and update it every time the file is saved. In this short post, I’ll just show the code and explain a bit about how it works.