1

I use vim for programming. my current job based on Yii MVC framework.

When you work with MVC framework, you are always navigating among models, controllers and views. I want to make save time navigation for my tasks.

The first is: i want jump to a model related controller. One model could have one controller for jumping to. Which i want to setup once in a project.

What is the best solution for this ?

My opinion is create a comment in a model header like phpDoc

/*
* @controller ControllerName
*/

And then write a vim function, which will find "ControllerName" in current file and open this file. Then bind it to a key combination.

What is your idea to implement it?

Thanks.

RusAlex
  • 8,245
  • 6
  • 36
  • 44

1 Answers1

2

This functionality is known as tag navigation. Chances are that your fileformat is already supported by the omnipresent exuberant ctags (guessing it is php, for sure).

Then you'd basically do:

:!ctags -R .
:tj ControllerName

You can use tab-completion (Control + Tab), do searches (:tj /troll + Tab)

Ctags has numerous options to enrich/limit the kinds of objects tagged. To selectively act on certain files only:

:tags +=controllertags
:!ctags -o controllertags **/*Controller.php

which will tag only controller sources in a separate tags file so you can keep working with the rest of your tags setup as before (in case you were already using it for other stuff)

sehe
  • 374,641
  • 47
  • 450
  • 633
  • you right, i can to fast jumping to a any tag with ctags, but now i have at least 20 controllers and it's alot of keys for typing (eveng with tab completition) when im juping. Therefore i want to describe a model-controller relation once, and then just pressing a one key combination,i will jump to my defined controller. – RusAlex Nov 18 '11 at 10:51
  • 1
    you could find some inspiration in the implementation of the 'standard' _alternate_ script ([a.vim](http://www.vim.org/scripts/script.php?script_id=31)) – sehe Nov 18 '11 at 10:52
  • for controllertags solution, how can i search tags only under controller tags ? – RusAlex Nov 18 '11 at 11:20
  • @RusAlex: you can't directly. However, you can define a function that saves the value of `tags`, sets `tags=controllertags`, executes the tag search, and restores the `tags` setting. Then map a command/key to call the function – sehe Nov 18 '11 at 12:37