This is an old question, but I keep coming back to it every now and then with a glimmer of fading hope, thinking that one day I'll find the right combination of plugins to give me perfect autocompletion in Vim. The search continues, but this is all the research I've done over the course of several years.
First of all, you must understand Vim is a text editor, not a code editor. Code editors, IDES, are tools like Jetbrains suite of tools, Visual Studio Code, Eclipse, etc.
Vim fundamentally can't "autocomplete" code accurately. Autocompletion requires introspecting your source code and analyzing the AST. Consider that Vim couldn't do asynchronous operations until Vim 8 was released in 2016, so trying to run any sort of code introspection software in a Vim plugin would be a nightmare. It's baked into the history of the Vim ecosystem not to do this. And all of the ones that try to do this, like Tern For Vim, are indeed nightmares to use.
The best a text editor can do is snippets and completing same words/lines/etc it knows about. If you're looking to autocomplete code, you should use a code editor, not a text editor.
These are your options, of which I've tried all:
Two useful keyboard shortcuts are Ctrl-n, which will auto-complete a word based only on the current buffers you have open (no code introspection), and Ctrl-xCtrl-l which will autocomplete a full line of code if you want to duplicate one. You probably know Ctrl-xCtrl-f, which will auto-complete a file name including path, relative to the current :pwd
. The pattern-complete plugin can be mildly useful if you don't search with /\v
.
Built in Vim "Omnicompletion" triggered by Ctrl-x,Ctrl-o (that's what Vim authors want you to type every time) along with a bunch of language specific plugins, if they exist. You can :echo &omnifunc
in a file to see if you already have Omnicompletion set up by Vim in your file of choice.
AutoComplPop for automatically opening the above Omnicompletion menu on typing.
SuperTab which lets you press Tab to trigger Vim's built in completion.
NeoComplCache which is keyword completion (how it's different from Vim's built in completion is not specified), a complex .vimrc
setup, and NeoSnippet for snippet completion.
A monster combination of exuberant-ctags
and DoctorJS
(a Mozilla project that has been dead for a year), TagBar and a home-grown thingy to extract completion from the tag files.
SnipMate, a basic tag completion plugin, along with snippets, and figure out on your own how to add snippets, as it's a bit tricky.
UltiSnips along with UltiSnips-Snippets which are different than the above snippets.
Tern for Vim, a promising library that does actual code introspection to get correct autocomplete. However it is buggy, very slow, has memory leaks that will crash Vim, and possibly is abandonware.
YouCompleteMe, a fuzzy as-you-type completion that runs a server in the background, along with a home-grown function for snippet completion.
Eclim - a noble attempt to run an Eclipse server in the background and tell Vim the autocompletions it introspects on the fly. It works about as well as Tern.
Finally, Closetag or delimitMate or autoclose or a home-grown bananagram for auto closing of tags and parenthesis automatically on typing.
Almost every plugin in this list will conflict with almost every other plugin in this list.
YouCompleteMe seems to be the leader of the pack, but I've never been able to get it to work properly with tag completion, and its code-introspection-completion has yet to prove powerful.
My personal opinion is that the current state of the Vim autocompletion world is in bad shape. For small projects you might be fine using one of the above solutions. If you're dealing with a simple API you can keep mostly in your head, non-code-introspection completion will probably be ok. If you are dealing with a large project, or need the benefit of type safety while programming, a full fledged IDE (Eclipse, Visual Studio, WebStorm) is going to suit you much better than Vim will.
The downside of an IDE, of course, is that you will not have the power of Vim at your hands anymore. I haven't used a single IDE that has an acceptable Vim mode.
Vim has a moderate language bias towards untyped C-like languages, and otherwise has the expectation that any language specific features will be added by users as plugins. Unfortunately, this has lead to a splintered autocompletion ecosystem. Some options are decent, but nothing is perfect, and there rarely is a majority leader / best practice.
You are doing crazy things with your setup. Did you find the default way too easy and solid?
Vim's runtime files, everything under /share/vim/vim74
, should be in /usr/share/vim/vim74
. Did you install Vim in your $HOME
because of privilege issues?
All your personal stuff (colorschemes, plugins, syntax scripts...) must go into ~/.vim
. That directory can be a symlink to that vimfiles
directory in your Dropbox which would remove the "need" for all your hacks. Assuming you are on Linux, just do:
ln -s /home/username/Dropbox/Personal/config_sync/vim/vimfiles /home/username/.vim
pathogen.vim
is not supposed to be source
d like that. It's in the autoload
directory precisely because the autoload
mechanism prevents it to be source
d in order to save time at startup.
Additionally, pathogen.vim
should be in ~/.vim/autoload/
.
With a "normal" setup, or a symlink that makes it look "normal" to Vim, there's no need to go through all those hoops.
smooth_scroll.vim
should not be in an autoload
directory, it comes in a plugin
directory, why did you change that? That's why the plugin doesn't work.
Did you know that 7.4 now looks both for ~/.vimrc
and for ~/.vim/vimrc
? It makes it a lot easier to manage your config by keeping everything in a single directory.
Step 1: change the structure of that vimfiles
directory in your dropbox to look like this:
/home/username/Dropbox/Personal/config_sync/vim/vimfiles/
+-autoload/
| +-pathogen.vim
+-bundle/
+-vim-smoothscroll/
+-plugin/
+-smooth_scroll.vim
Step 2: move your vimrc
inside the vimfiles
directory in your dropbox.
step 3: remove all the useless path-related stuff in that file. The pathogen-related part should look like this:
execute pathogen#infect()
execute pathogen#helptags()
step 4: remove your ~/.vimrc
:
$ cd
$ unlink .vimrc
step 5: create a symlink to your dropbox-synced directory:
$ ln -s /home/username/Dropbox/Personal/config_sync/vim/vimfiles /home/username/.vim
Best Answer
Without looking at your complete
.vimrc
I would adventure to say that you should set the flag for non-vi compatibility:set nocompatible
That should be the first thing (or one of the first things) in your
.vimrc
The Vim version that comes with OSX is not only a bit behind but it is also not compiled with a bunch of features plugins require. Some plugins don't even load at all if the version is not compatible with the ones they support.
Finally, I would start Vim with the verbose flag on (
vim -V
) where you can see all the output of what exactly Vim is loading and looking for.This answer is somewhat vague, but there are just too many things that can happen to get that behavior. I just mentioned the top 3 on my list: latest Vim version compiled with
huge
flag,set nocompatible
in your.vimrc
and load Vim with the verbose flag.