Autocomplete Method Structure in Vim

Autocomplete method structure in Vim

vim-endwise does this (I've been happy enough with it to not uninstall it, so I guess that's an endorsement even).

vim autocomplete on certain keywords

there seems to be a plugin named endwise. I have never tried but it sound like what you need.

Configure VIM YouCompleteMe for special project structure

I think my project structure is really lame, as said by pepper_chico, but no choice, I can't change it. In the passed few days, I did some hacking to both YouCompleteMe and libclang by change the API call of libclang to pass input_filename in additional to complte_filename.

This is a dirty hacking, but it works for me now. In case anyone might interesting, I have write a post to briefly record down my analysis and hacking process.

  • My Post

Update 2015-02-03

1 Year later, when I look back at this problem, I finally figured out a better way to hack YouCompleteMe for my need. Details look here

My modification on GitHub here, take note the branch name is lamely for now.

List @ tag auto completes in vim

After quite a bit of struggling and searching for help, I figured out one solution.

Firstly create a completefunc that searches for @tags in the current file (Credits to cherryberryterry: https://www.reddit.com/r/vim/comments/4dg1rx/how_to_define_custom_omnifunc_in_vim_seeking/):

function! CompleteTags(findstart, base)
if a:findstart
return match(matchstr(getline('.'), '.*\%' . col('.') . 'c'), '.*\(^\|\s\)\zs@')
else
let matches = []

" position the cursor on the last column of the last line
call cursor(line('$'), col([line('$'), '$']))

" search backwards through the buffer for all matches
while searchpos('\%(^\|\s\)\zs' . (empty(a:base) ? '@' : a:base) . '[[:alnum:]_]*', 'bW') != [0, 0]
let matches += [matchstr(getline('.'), '\%' . col('.') . 'c@[[:alnum:]_]*')]
endwhile

return filter(matches, "v:val != '@'")
endif
endfunction
set completefunc=CompleteTags

The put the following in .vimrc to setup tab-completion using SuperTab:

function! TagCompleteContext()
let line = getline('.')
if line[col('.') - 2] == '@'
return "\<c-x>\<c-u>"
endif
endfunction

let g:SuperTabDefaultCompletionType = "context"
let g:SuperTabCompletionContexts = ['TagCompleteContext', 's:ContextText']
let g:SuperTabContextDefaultCompletionType = "<c-p>"

Auto code completion in VIM?

Try to use http://eclim.org/ - using eclipse core with VIM via plugins.

To not start the complete ecplise core but have a C/C++ member completion, try
http://www.vim.org/scripts/script.php?script_id=1520

-   Complete namespaces, classes, structs and union members. 
- Complete inherited members for classes and structs
(single and multiple inheritance).
- Complete attribute members eg: myObject->_child->_child etc...

How do I make Vim do normal (Bash-like) tab completion for file names?

I personally use

set wildmode=longest,list,full
set wildmenu

When you type the first tab hit, it will complete as much as possible. The second tab hit will provide a list. The third and subsequent tabs will cycle through completion options so you can complete the file without further keys.

Bash-like would be just

set wildmode=longest,list 

but the full is very handy.

Vim and python: context-unaware autocompletion of language methods

You definitely should take a look at PySmell which can be installed for Vim easily. It generates a completion menu based on a static analysis for a given project. It also can generate completion suggestions based on tags it produces for external libraries like the Python Standard Library or Django Lib.

I was happy with Vims Python omnicimpletion, but since I switched to PySmell, I never looked back.

Vim, Python, and Django autocompletion (pysmell?)

First off, thank you for asking this question, as it forced me to figure this out myself and it's great!

Here is the page I used as a reference: PySmell v0.6 released : orestis.gr

  1. Install PySmell using the setup.py install command.
  2. Generate the PYSMELLTAGS file for django by going to your site-packages/django directory and running: pysmell . -o ~/PYSMELLTAGS.django
  3. Copy that file to your project directory, and then ran pysmell . to generate the project PYSMELLTAGS file
  4. Make sure pysmell is in your PYTHONPATH (export PYTHONPATH=${PYTHONPATH}:/path/to/pysmell/)
  5. Run vim (vim .)
  6. Source pysmell.vim (:source /path/to/pysmell/pysmell.vim)
  7. Set the autocomplete command (:set omnifunc=pysmell#Complete)
  8. Type ^x^o to autocomplete and it should work

I realize this is not a sustainable solution, but you should be able to use this as a start to getting it setup to always work (e.g., add the export to your .bashrc, add the :source to your .vimrc, setup autocmd FileType python set omnifunc=pysmell#Complete, etc.)

Let me know if this is enough to get you started. It worked for me!

Edit
I simply added this to my .vimrc and as long as the PYSMELLTAGS & PYSMELLTAGS.django files are in my project root, it works fine without any other work:

python << EOF
import os
import sys
import vim
sys.path.append("/usr/local/python/lib/python2.5/site-packages")
EOF
exe ":source ~/src/pysmell/pysmell.vim"
autocmd FileType python set omnifunc=pysmell#Complete

Vim autocomplete: Cancelling autocomplete popup

Ctrl+E will end the current completion and put back that originally typed text.

See

:h complete_CTRL-E
:h ins-completion


Related Topics



Leave a reply



Submit