Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim plugin to auto complete across multiple open buffers

Is there a vim plugin that does auto completion across multiple files?

Example:

  • Open files are a.txt and b.txt.
  • While using vim to edit b.txt, I want to be able to receive auto completion results from a.txt and b.txt

I already use the youCompleteMe plugin, but that only does completion in one file for methods from that language.

Any suggestions?

like image 874
applejuiceteaching Avatar asked Dec 25 '22 00:12

applejuiceteaching


1 Answers

Vim’s built-in completion with Ctrl-N in Insert Mode already supports this. There is no need for a plug-in.

You can see that with the following test:

  1. Create a file very-basic-vimrc with the following contents:

    set nocompatible
    filetype plugin indent on
    syntax enable
    
  2. Run vim -u very-basic-vimrc. That launches Vim using that file as your vimrc, so you can test how Vim works without any plugins.

  3. In the empty buffer, type the text “one two three”.

  4. Run :new to open another buffer, and type “four five six”.

  5. Switch back to the first buffer with Ctrl-W W, then open a new line with o.

  6. Type “fi” and press Ctrl-N. This triggers the next autocomplete match – see Vim’s documentation for i_CTRL-N. “five” will successfully be completed, even though the word “five” is in a different buffer.

If this functionality is not working for you with your normal vimrc, one of your installed plugins such as YouCompleteMe might be interfering with that behavior. Change the settings for that plugin or disable it.

I personally use Supertab. With Supertab, I can successfully type Tab to complete a word from a different buffer. Other popular completion plugins probably support that feature too.

I see that YouCompleteMe purports to offer completion without even needing to type Tab. If completions from other buffers do not show up in that automatically-triggered list, YouCompleteMe probably does it on purpose so that normal typing won’t be slowed down too much. You would have to look in YCM’s documentation for an option that enables it, or a mapping that expands the completion list to include completions from other buffers. If neither of those exist, you could create an issue requesting that on YouCompleteMe’s issue tracker.

like image 71
Rory O'Kane Avatar answered Dec 28 '22 08:12

Rory O'Kane