Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim function hints for C

I'm trying to achieve something simple, usually called "function hints". For example, scintilla-based editors have it:

enter image description here

You type a name, and just get the prototype. There are a few problems with that in vim:

  • You have to rebuild the ctags to keep it up to date
  • You can't type C-X C-O after the (, you'll just get "Pattern not found"
  • You can't type C-X C-O in normal mode, the cursor will just jump around
  • You get the annoying preview window at the top

I've tried a few plugins; most of them mess things up even more [^1].Can anyone recommend a simple way to get just that ? A simple rectangle containing the function prototype and nothing more.

[^1] It's really mind-numbing how idiotic some of these plugins are. One plugin (I won't mention it) actually contained in the .vim file a list of functions from libc.

like image 662
user1497069 Avatar asked Jul 02 '12 20:07

user1497069


1 Answers

ctags for autocompletion is a mess. I suggest you try a compiler based plugin such as clang-complete or gcc-sense (haven't tried this one). Advantages are:

  • more accuracy as what they do is pretty much compiling
  • compile errors are marked on the fly over the source code

You have to rebuild the ctags to keep it up to date

you don't need to deal with ctags (they are still useful to jump around though)

You can't type C-X C-O after the (, you'll just get "Pattern not found"

what would you expect?

You can't type C-X C-O in normal mode, the cursor will just jump around

you can always remap that sequence if you think it's a frequent mistake (something like nnoremap <C-x><C-o> a<C-x><C-o>)

You get the annoying preview window at the top

You can disable this by removing preview fromcompleteopt option. see :help completeopt

I'm using the following setup:

here

  • clang-complete for completion
  • supertab to complete with tab key
  • ultisnips for function signature placeholders. (also works with snipmate)

and some vimrc settings:

set pumheight=10             " so the complete menu doesn't get too big
set completeopt=menu,longest " menu, menuone, longest and preview
let g:SuperTabDefaultCompletionType='context'
let g:clang_complete_auto=0  " I can start the autocompletion myself, thanks..
let g:clang_snippets=1       " use a snippet engine for placeholders
let g:clang_snippets_engine='ultisnips'
let g:clang_auto_select=2    " automatically select and insert the first match

Enjoy!

like image 196
none Avatar answered Sep 29 '22 03:09

none