By default code completion in VIM searches from the start of the word. Is it possible to make it anywhere in the word. For example, if I have “MY_DEVICE_CTRL_ADR” and “MY_DEVICE_STAT_ADR” in the C header file, can i start typing CTRL_ and then have VIM complete it for me?
Share
Okay, this is very rough-and-ready, but it appears to work (at least in simple cases).
First of all here is a function which performs a vimgrep on a given a file. This needs to be a separate function so it can be called silently later on.
Now here is a custom-completion function which calls
File_Grep()and returns a list of matching words. The key is the call to theadd()function, which appends a match to the list if search term (a:base) appears ANYWHERE in the string. (Seehelp complete-functionsfor the structure of this function.)Then you just need to tell Vim to use the complete function:
and you can use
<c-x><x-u>to invoke the completion. Of course, the function could be used to search any file, rather than the current file (just modify thelet fnameline).Even if this isn’t the answer you were looking for, I hope it aids you in your quest!