Question

After using XCode for a while (couple years), I'm attempting to move to MacVim for development/code editing. Mostly, I'm doing this because I'm starting up some non-obj-c projects and I don't want to keep switching between code editors.

I've setup MacVim with a few convenient plugins:

  • Janus (which is a host of plugins, I know)
  • cocoa.vim
  • clang_complete, which is the most important one to me, since it mimics XCode's code completion.

So far everything works fine except I can't seem to configure it to popup the completion box automatically. I have to use "tab" every time I want to view the code completion. I'd rather it open up after a certain number of characters for a word are entered, say 3 characters. I've searched around for a while (couple hours) but haven't been able to get it to work.

Any help would be appreciated. Thanks!
Here's my .vimrc file:

""
"" Janus setup
""

" Define paths
let g:janus_path = escape(fnamemodify(resolve(expand("<sfile>:p")), ":h"), ' ')
let g:janus_vim_path = escape(fnamemodify(resolve(expand("<sfile>:p" . "vim")), ":h"), ' ')
let g:janus_custom_path = expand("~/.janus")

" Source janus's core
exe 'source ' . g:janus_vim_path . '/core/before/plugin/janus.vim'

" You should note that groups will be processed by Pathogen in reverse
" order they were added.
call janus#add_group("tools")
call janus#add_group("langs")
call janus#add_group("colors")

""
"" Customisations
""

if filereadable(expand("~/.vimrc.before"))
  source ~/.vimrc.before
endif


" Disable plugins prior to loading pathogen
exe 'source ' . g:janus_vim_path . '/core/plugins.vim'

""
"" Pathogen setup
""

" Load all groups, custom dir, and janus core
call janus#load_pathogen()

 colorscheme Wombat256

 "clang_autocomplete options
 set conceallevel=2
 set concealcursor=vin
 let g:clang_use_library=1
 let g:clang_library_path='/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib'
 let g:clang_complete_auto=1
 let g:clang_periodic_quickfix=1
 let g:clang_snippets=1
 let g:clang_conceal_snippets=1
 let g:clang_snippets_engine='clang_complete'
 " Show clang errors in the quickfix window
 "let g:clang_complete_copen = 1
 set completeopt=longest,menuone,preview
Was it helpful?

Solution

This can be achieved using AutoComplPop (vimscripts, old / Github, somewhat old).
The number of characters needed to be entered before it'll try keyword completion can also be set.

let g:acp_behaviorKeywordLength = 3

Note that the the newer versions requires the L9 library. The old one at vimscripts does not.
It's kind of confusing since there's different versions on all the different sites (vimscripts, github, bitbucket).

Install the plugin(s) using your favorite plugin manager.
Personally I prefer Vundle, but Janus uses Pathogen.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top