Is there a vim plugin that does auto completion across multiple files?
Example:
a.txt
and b.txt
. 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?
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:
Create a file very-basic-vimrc
with the following contents:
set nocompatible
filetype plugin indent on
syntax enable
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.
In the empty buffer, type the text “one two three”.
Run :new
to open another buffer, and type “four five six”.
Switch back to the first buffer with Ctrl-W W, then open a new line with o
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With