Using Ember-Cli With Vim and .swp Files


TL;DR: If you’re using vim with ember-cli, move your .swp files out of your project directory by adding set directory=~/.vim/_tmp// to your .vimrc.

I’ve recently decided to revisit ember.js and work up a little prototype application with it. The last time I tried ember seriously was just before version 1.0.0 - I think it was 1.0-rc1 or so.

Since then, the tooling has come a long way, and I’ve had a great experience getting up and running with ember development using the ember-cli set of tools. Being able to get a functioning server running with just $ ember server is pretty fantastic, and has gone a long way to avoiding problems that usually come with working on static sites using a file:/// url.

However, I did run into a small problem - ember-cli’s Broccoli builder re-builds the project on any change in the project directory - including changes to ‘hidden’ files, like the .filename.swp and .filename.swo files that vim creates automatically to store temporary changes.

As such, whenever I saved a change, Broccoli would build the app, which takes about 300ms, then automatically reload the project in my browser, then the .swp file would change, and Broccoli would build the project again, and then the browser would reload again, a full second later - and inevitably after I had already started interacting with the application.

I was lucky enough to catch Robert Jackson (@rwjblue), an ember core team member, on twitter, and he helpfully told me that (a) there is no way to have Broccoli ignore a file type, as of now, and that (b) I could move my .swp files out of the project directory by setting directory variable in vim. He was even kind enough to link me to his dotfile on github, which contained the following two lines:

set directory=~/.vim/_tmp//

set backupdir=~/.vim/bakcup//

Adding these two lines to the .vimrc file causes vim to store all of its temporary files in the specified directories, not your project directory - so Broccoli has nothing to mistakenly rebuild off of.

And, thanks to Robert and the ember team for all their work on ember and ember-cli!

Get Notified of New Posts

* indicates required