Live data from Hacker News

Built-In Vim Autocomplete

github.com

1–10 of 30 posts

Re: Built-In Vim Autocomplete

#3
Bonus: If you have set up a tags file, the symbols there will also be available by default with autocomplete. This can help fill out a lot of potential functions and keywords which might not normally be set up (for Python, I set up a tagfile for both the standard library and site packages).

See ':help cpt' and ':help ins-completion'

YouCompleteMe is a good plugin for expanding out autocompletion for a lot more languages, but the built-in autocompletion is remarkably good out of the box.

Re: Built-In Vim Autocomplete

#4
post #2

This whole time I had no idea vim could autocomplete

This is classic "string-based" autocomplete. It completes based on strings it knows about but doesn't take into account the context. I've used for years but yesterday I realized that since Vim version 7 there's a more intelligent kind of autocomplete triggered by C-x C-o that is context-aware. It can complete object methods, HTML tag attribtes, CSS properties, etc. For info:

    :help new-omni-completion

Re: Built-In Vim Autocomplete

#5
post #3

Bonus: If you have set up a tags file, the symbols there will also be available by default with autocomplete. This can help fill out a lot of potential functions and keywords which might not normally be set up (for Python, I set up a tagfile for both the standard library and site packages). See ':help cpt' and ':help ins-completion' YouCompleteMe is a good plugin for expanding out autocompletion for a lot more langua…

If you have a tags file set up, vim omnicomplete () for C and C++ (at least) will also be able to complete struct/class members and other context sensitive.

Additionally, I set the user complete mode () to use vim's built in syntax complete (`:set completefunc=syntaxcomplete#Complete`), which is super helpful with e.g. config files because Vim is aware of all the available completion options.

Of course there's filename complete too ().

These three modes can get some intelligent completion done but quite frankly the default local keyword completion covers 90% of my use cases.

Re: Built-In Vim Autocomplete

#6
Here is a way to bind autocomplete to TAB such that you still get TAB unless you are at the end of a word to complete. It's super convenient.

    function! InsertTabWrapper()
      let col = col('.') - 1
      if !col || getline('.')[col - 1] !~ '\k'
        return "\"
      else
        return "\"
      endif
    endfunction
    inoremap  =InsertTabWrapper()

Re: Built-In Vim Autocomplete

#8
Vim's autocomplete is alright, but it can definitely be super-charged by plugins like vim-autocomplpop[0], superTab, and language specific plugins like vim-racer[1].

Vim-autocomplpop is a fairly old plugin, but it still works just fine. It automatically shows autocompletion options as you type like an IDE. This is very handy.

The only downside is that external autocompletion engines like ctags and rope can sometimes cause performance issues. For example, python.vim uses rope to analyze a file, but that can take a while to initialize and crawl directories if you're editing a file in your home directory. Since it's a plugin written before Vim/Neovim's async code, it tends to make Vim unresponsive, so I only enable vim-autocomplpop on projects I'm working on. This isn't an issue if you use Vim's built-in autocomplete (instead of python.vim). I'll get around to rewriting autocomplpop someday and working on a solution to mitigate external autocomplete providers slowing down Vim.

0: https://github.com/othree/vim-autocomplpop 1: https://github.com/racer-rust/vim-racer

Re: Built-In Vim Autocomplete

#9

Vim's autocomplete is alright, but it can definitely be super-charged by plugins like vim-autocomplpop[0], superTab, and language specific plugins like vim-racer[1]. Vim-autocomplpop is a fairly old plugin, but it still works just fine. It automatically shows autocompletion options as you type like an IDE. This is very handy. The only downside is that external autocompletion engines like ctags and rope can sometimes…

Have you tried YouCompleteMe? I'm surprised you didn't mention it.
Post reply on HN