5

When doing auto completion with CTRL+n, I see autocompletion suggestions from the current file as well as from different other files all mixed together as seen below:

enter image description here

I would like to get a behavior similar to what is shown on the below picture, i.e. display the path of the file containing the suggestion if the suggestion is coming from file other than the current one.

enter image description here

8
  • Where is the image from ?
    – D. Ben Knoble
    Dec 30, 2020 at 15:11
  • 1
    @D.BenKnoble from this video in the autocompletion section: youtu.be/XA2WjJbmmoM
    – BiBi
    Dec 30, 2020 at 15:17
  • Perhaps this is related to the version of Vim... Which version are you using? I just tested this on 8.2.1704 and I see the behavior that includes the filenames... But I do recall seeing the menu without any filenames in the past, so it's possible that this was a somewhat recent addition.
    – filbranden
    Dec 30, 2020 at 21:02
  • 1
    I'm using version 8.2.2200 which is even more recent. Also, the video dates back to 2016.
    – BiBi
    Dec 30, 2020 at 21:28
  • 1
    I edited the question with a screenshot of the currently observed behavior.
    – BiBi
    Dec 31, 2020 at 1:03

2 Answers 2

0

Normally it work if you have your file opened as buffer in vim. The autocompletion will look at them when you launch CTRL_P or CTRL_N (see :help complete):

'complete' 'cpt'        string  (default: ".,w,b,u,t,i")
                        local to buffer
        This option specifies how keyword completion ins-completion works
        when CTRL-P or CTRL-N are used.  It is also used for whole-line
        completion i_CTRL-X_CTRL-L.  It indicates the type of completion
        and the places to scan.  It is a comma separated list of flags:
        .       scan the current buffer ('wrapscan' is ignored)
        w       scan buffers from other windows
        b       scan other loaded buffers that are in the buffer list
        u       scan the unloaded buffers that are in the buffer list 
        U       scan the buffers that are not in the buffer list
        k       scan the files given with the 'dictionary' option
        kspell  use the currently active spell checking spell
        k{dict} scan the file {dict}.  Several "k" flags can be given,
                patterns are valid too.  For example:
                        :set cpt=k/usr/dict/*,k~/spanish
        s       scan the files given with the 'thesaurus' option
        s{tsr}  scan the file {tsr}.  Several "s" flags can be given, patterns
                are valid too.
        i       scan current and included files
        d       scan current and included files for defined name or macro
                i_CTRL-X_CTRL-D
        ]       tag completion
        t       same as "]"
4
  • 1
    The question is not about just completing from keywords found in other buffers... But about listing the name of the file/buffer where that keyword is coming from. See the screenshot, the right column lists file paths (lib/tella.rb and lib/tella/server/tcp.rb for the three first keywords.)
    – filbranden
    Dec 30, 2020 at 19:29
  • @filbranden this is strange. Normally it works without any specific configuration. I also tried it with an empty vimrc and the classic vi editor and the name of the file/buffer appeared like in your screenshot. I was wondering if you might have changed a setting by accident. That's why I give you this response. But if your vimrc is clean, thats a mystery. I will try to see another solution, but there is no guarantee that I will find one. Dec 30, 2020 at 20:49
  • Just tried on macOS with version 8.2.2200 and on Ubuntu with version 8.2.1897 with an empty .vimrc and I don't observe the desired behavior.
    – BiBi
    Dec 30, 2020 at 21:35
  • I can confirm @FabriceHategekimana's comment: it should show filenames beside the completion entry. It shows on both my nvim 8.0 and vim 8.1. Both with --clean.
    – 3N4N
    Sep 22, 2022 at 5:01
0

Assuming you are using the built-in :help ins-completion, I can only think of two reasons why the name of the buffer where the suggestion comes from is not displayed:

  • The buffer is unnamed.
  • The keyword is also present in the current buffer.

In the screenshot below, taken in $ vim -Nu NONE, foo doesn't get a bufname because it is already in the current buffer, football and foobar both get a bufname because they are from buffer foo (naming is hard), and icare doesn't get a bufname because it is from an unnamed buffer.

demo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.