views:

182

answers:

1

I'm editing a simple PHP file with a class which has a few methods, if $bar is an instance of this class and I type

$bar->ctrlxctrlo

I get a popup with a lot of methods (builtin ones) in addition to those of my class and present in the ctags list. How can avoid showing all those external methods and just keep the ones defined in my class?

+1  A: 

I'm sure you've seen the VIM documentation (:help ft-c-omni) for this:

When using CTRL-X CTRL-O after a name without any "." or "->" it is completed from the tags file directly. This works for any identifier, also function names. If you want to complete a local variable name, which does not appear in the tags file, use CTRL-P instead.

When using CTRL-X CTRL-O after something that has "." or "->" Vim will attempt to recognize the type of the variable and figure out what members it has. This means only members valid for the variable will be listed.

When a member name already was complete, CTRL-X CTRL-O will add a "." or "->" for composite types.

If I read that correctly, the built-in functionality will, at best, only allow you to use CTRL-P and match the local variables names thus bypassing the TAGS file altogether.

What you really want is a TAGS file that is specific to the translation unit that you're currently working on (header/cpp file). Here are the steps that I would perform if I were trying to solve this problem:

  1. Create a script (or better yet, incorporate into a makefile) the automatic creation of translation unit specific TAG files.
  2. Create a command in vim that unloads existing TAGS files, reloads the file specific TAGS file, and performs regular CTRL-X CTRL-O omni-completion. If necessary, revert to the original TAGS.

Also, it seems to me like you would want to be able to call the script for #1 directly from VIM since you would be frequently changing the current translation unit as you code.

I hope that gets you started in the right direction, and I'd be happy to see / help you with an implementation =).

reshen
Nope, I'm writing PHP code, not C++. Documentation states `after "->" complete only function and variable names specific for given class` but that's not the behavior I'm getting.
kemp
You are correct, my mistake. If you are in compliance with the requirements (Exuberant ctags 5.5.4/newer) and have tried the @var trick; thats a very strange problem. It's almost as if the tags are defaulting to global scope when they can't find anything more specific (variable's class).
reshen