Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6782919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:48:06+00:00 2026-05-26T16:48:06+00:00

By default code completion in VIM searches from the start of the word. Is

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:48:07+00:00Added an answer on May 26, 2026 at 4:48 pm

    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.

    function! File_Grep( leader, file )
        try
            exe "vimgrep /" . a:leader . "/j " . a:file
        catch /.*/
            echo "no matches"
        endtry
    endfunction
    

    Now here is a custom-completion function which calls File_Grep() and returns a list of matching words. The key is the call to the add() function, which appends a match to the list if search term (a:base) appears ANYWHERE in the string. (See help complete-functions for the structure of this function.)

    function! Fuzzy_Completion( findstart, base )
        if a:findstart
            " find start of completion
            let line = getline('.')
            let start = col('.') - 1
            while start > 0 && line[start - 1] =~ '\w'
                let start -= 1
            endwhile
            return start
        else
            " search for a:base in current file
            let fname = expand("%")
            silent call File_Grep( a:base, fname )
            let matches = []
            for this in getqflist()
                call add(matches, matchstr(this.text,"\\w*" . a:base . "\\w*"))
            endfor
            call setqflist([])
            return matches
        endif
    endfunction
    

    Then you just need to tell Vim to use the complete function:

    set completefunc=Fuzzy_Completion
    

    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 the let fname line).

    Even if this isn’t the answer you were looking for, I hope it aids you in your quest!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suggest me, is it a good idea to make changes in default Joomla code
I have some code using Lucene that leaves the default conjunction operator as OR,
I have the following code in a web.config file of the default IIS site.
I have the following code: private static void WriteStartupInfo() { Settings settings = Settings.Default;
I have some code that sets the lang var to the site default language.
I have the following code that I expect to run successfully to completion but
I have a number of stored procedures I call from code with ExecuteNonQuery .
I am trying to create DependencyProperties that have a nice drop down code completion
I would like to make work the source code completion for Opencv 2.3 on
How to set the default style for a type in code-behind e.g. for: <ScaleTransform

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.