7

I am developing main in Rails using SASS, Slim and Coffeescript. I have Exuberant Ctags installed and using tpope's setup

It kind of works so at least I can move around my ruby code.

But I would like to be able to:

SASS
color: $whatever    <- go to that color
@extend %something  <- go to that mixin
+another()          <- go to that include

HTML/SLIM
.nice_class         <- go to that class in .sass file
#id                 <- find JS files using this #id

RUBY
has_many :something <- go to that class
concerns :important <- go to that symbol

And maybe the most important – I want to autocomplete on the above. So I can reuse CSS classes, HTML ID's and Ruby symbols in the project.

How to set up Ctags to cover css classes, html id's, sass mixins, and everything else used in modern web development?

  • That seems to be well beyond the ken of simple tags and more the level of something like cscope, but I don't know if cscope supports HTML+JS+CSS. – muru Mar 19 '15 at 12:55
  • 1
    You could take a look at this SO question. – romainl Mar 19 '15 at 12:59
3

Vim is a powerful text editor. The tags feature is based on a simple foundation: Vim can read one or several tags databases, which contain line-based records consisting of a tag (basically a string), a corresponding file and address (search pattern) to locate it, and optional additional information.

That's what you get: If you build a tags file covering your Ruby, SASS, and CoffeeScript, you can jump to defined tags and use completion. However, beyond this simple, easy-to-understand mechanism, Vim has no capabilities of distinguishing various languages and symbols based on syntax or sigils. While you could build come custom intelligence around this, you'd move into the direction of building an IDE, which Vim isn't. Better accept the limitations and use Vim where it excels, and stick to an IDE for the rest.

TL;DR: Vim is a language-agnostic text editor with basic navigation means, for full capabilities, use an IDE for navigation.

  • 1
    I know Vim doesn't understand the language it edits. Is there a way to set up Ctags so it collects everything that begins with a dot, hash, percent-sign etc? PS. Thanks for camelcase motion. – firedev Mar 19 '15 at 14:06
  • 1
    Exuberant ctags has rules for it's supported languages built-in; I don't think you can change those. But you can define your own, regexp-based parsing via --langdef=... --langmap=... --regex-...=... – Ingo Karkat Mar 19 '15 at 14:12
  • 2
    "Better accept the limitations and use Vim where it excels, and stick to an IDE for the rest". @IngoKarkat That makes no sense. You are saying switching back and forth between Vim and an IDE is more ideal than customizing Vim to do everything you want. It would be better to have a customized Vim that does everything you want exactly the way you want. You are giving up too easily. Don't give up. Vim + Linux + shell = text based IDE. You can get it to do anything you want within the concept of a text based IDE. – still_dreaming_1 Mar 20 '15 at 3:15
  • @INTPnerd: At least for certain languages, IDEs are very far ahead in functionality; for brevitiy, just two things where it'll be hard for Vim to keep up: fancy GUI visualizations (ruled out of scope by Bram), and asynchronicity (hard to implement). I personally use IntelliJ IDEA and GVIM in parallel, and am quite satisfied with that "best of both worlds" setup. – Ingo Karkat Mar 20 '15 at 8:07
  • @IngoKarkat That only works for certain things. But as far as good support for code lookup/navigation, these are things you want to have working really well inside vim whenever you are using it. It would not make sense to be editing code in vim, and then switch to an IDE to lookup a piece of code so that you can edit it inside Vim. So far I have never been happy with any Vim emulation I have seen inside an IDE. I always end up missing full Vim with all the customizations and plugins I have for it. This becomes more and more true the longer you use and thus customize/extend Vim to your liking. – still_dreaming_1 Mar 20 '15 at 22:41
1

Try vim-gutentags: https://github.com/ludovicchabant/vim-gutentags It automatically generates tags for you. A word of warning though, this plugin will automatically regenerate tags after each save so it might slow you down overall. Also it'll generate tags for whatever file you have opened so you might end up with tags file in your dotfiles folder. If you want to disable tags generation for project read this: https://github.com/ludovicchabant/vim-gutentags/commit/7316197a7f884e264e20590cbad90046d8337fbb

Personally I've been using it for quite some time and if configured properly this plugin can be a huge time saver but YMMV.

  • Just disabled easytags plugin that was slowing vim down vi.stackexchange.com/a/2897/237 and switched to using git hooks as suggested by tpope – firedev Apr 13 '15 at 5:06
  • ^ Which didn't work that well either. – firedev May 7 '16 at 4:22
1

There is a nice post on using git hooks for managing ctags by tpope:

http://tbaggery.com/2011/08/08/effortless-ctags-with-git.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.