Some niceties for using vim with the AngularJS framework.
:A
A, the "alternate" file, has been mapped to take you from your code to the corresponding test file, or from your test file to the corresponding implementation file. For example, if you're in app/js/rock-socks.js, and you hammer :A, you will be taken to test/spec/rock-socks.js, if such a file exists. Some other common directory structure conventions in the angular community, such as app/src and test/unit, are also supported. Feel free to file a pull request if your reasonable convention doesn't work.
gf
"Go to file" has been slightly overriden to take you to the definition of the file under your cursor. If you're reading some code like this...
if (true) {
AwesomeService.changeStateBecauseMutationIsAwesome();
}...and your cursor is on AwesomeService, and you hammer gf, if there is a
file called awesome-service.js somewhere in a subdirectory of your path,
you will be taken there. The default behavior of gf can also be quite
useful in the context of an angular app, since html fragments are specified
as file paths in views (with ng-include src="full/path.html), directives
(with templateUrl: 'src/myapp/modules/main/views//prompt-list.html', so an
attempt has been made to allow this to work as well. If all that is missing
from a template path is the "app" directory (which is a common value for
"cwd" in Gruntfile.js, the plugin will add this for you as well. If either
of these two things don't work for your use case, file a ticket, figure
out why and file a pull request, or use ctags.
If you're writing jasmine unit tests for your angular app, they look like this:
it('should work', function() {
var actualThing = 'cow';
expect(actualThing).toEqual('cow');
});Now, if you take that "it" prefix, and replace it with "iit", instead of running your entire suite, it will run JUST THAT ONE SPEC. There are probably bad reasons to want to do this, like if your build is broken and you only want to fix your code, but it can be pretty handy to focus in on just one spec at a time (and one spec generally runs way fast).
So, if you're anywhere inside a spec:
:AngularRunSpec
or the "go run spec" mapping:
grs
will toggle the spec between "it" and "iit." This works especially well if you have a karma watch going. See the screencast.
-
Using Pathogen, run the following commands:
% cd ~/.vim/bundle % git clone git://github.com//burnettk/vim-angular.git -
Using Vundle, add the following to your
vimrcthen run:BundleInstallBundle "burnettk/vim-angular"
Once help tags have been generated, and I have written the helpfile, you
can view the manual with
:help angular.
Like vim-angular.vim? Follow the repository on GitHub and vote for it on vim.org. And if you're feeling especially charitable, follow burnettk on Twitter and GitHub.
Copyright (c) Kevin Burnett. Distributed under the same terms as Vim itself.
See :help license.