Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Vim gives me too much options when I use code completion. In a class, and type $class-> it gives me about a zillion options, so not only from the class itself but also from php, all globals ever created, in short: a mess.

I only want to have the options from the class itself (or the parent subtype class it extends from), so context or scope sensitive code completion, just like Netbeans for example. How can I do that?

My current configuration is this:

I am using ctags, and created 1 ctags file for our (big) application in the root.

This is the .ctags file I used to create the ctags file:

-h ".php"
--regex-PHP=/abstract\s+class\s+([^ ]+)/\1/c/
--regex-PHP=/interface\s+([^ ]+)/\1/c/
--regex-PHP=/(public\s+|static\s+|protected\s+|private\s+)\$([^ \t=]+)/\2/p/
--regex-PHP=/const\s+([^ \t=]+)/\1/d/
--regex-PHP=/final\s+(public\s+|static\s+|abstract\s+|protected\s+|private\s+)function\s+\&?\s*([^ (]+)/\2/f/

This is the .vimrc file:

" autocomplete funcs and identifiers for languages
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete

" exuberant ctags
" the magic is the ';' at end. it will make vim tags file search go up from current directory until it finds one.
set tags=projectrootdir/tags;
map <F8> :!ctags

" TagList
" :tag getUser => Jump to getUser method
" :tn (or tnext) => go to next search result
" :tp (or tprev) => to to previous search result
" :ts (or tselect) => List the current tags
" => Go back to last tag location
" +Left click => Go to definition of a method
" More info:
" (official documentation)
" (a vim tip)
let Tlist_Ctags_Cmd = "~/bin/ctags"
let Tlist_WinWidth = 50
map <F4> :TlistToggle<cr>

" will change the 'completeopt' option so that Vim's popup menu doesn't select the first completion item, but rather just inserts the longest common text of all matches
:set completeopt=longest,menuone
" will change the behavior of the <Enter> key when the popup menu is visible. In that case the Enter key will simply select the highlighted menu item, just as <C-Y> does
:inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
inoremap <expr> <C-n> pumvisible() ? '<C-n>' :
  \ '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'

inoremap <expr> <M-,> pumvisible() ? '<C-n>' :
  \ '<C-x><C-o><C-n><C-p><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
share|improve this question

migrated from Oct 9 '12 at 21:11

This question came from our site for professional and enthusiast programmers.

With the default PHPComplete, you have to generate your tags each time you do $foo = new MyClass. If you do that you'll get correct completion.

But there's another PHPComplete script that fixes this issue. You should try it.

share|improve this answer
Thx for your answer. I have tried phpcomplete, but still got a lot of options. Maybe I have php ftplugin not enabled. Any idea how to do that? – eddy147 Oct 15 '12 at 6:54
That script is to be put in ~/.vim/autoload/. If the ~/.vimrc in your question is exactly what you have on your machine, a very important piece is missing: filetype plugin indent on. – romainl Oct 15 '12 at 7:01
Put phpcomplet.vim in ~/.vim/autoload, and added "filetype plugin indent on" in ~/.vimrc, but still get all kinds of options... – eddy147 Oct 17 '12 at 18:28
Well, I don't know how to fix your situation. It works very well here. – romainl Oct 17 '12 at 19:19
With this very basic setup, <c-x><C-o> only proposes me __construct( and publicMethod( when I'm at the arrow. – romainl Oct 17 '12 at 19:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .