0

Is there way in VIM to have a keystroke invoke a drop-down menu (similar to code completion) , but lists lines of text from a text file to choose from?

I have a list of macros that I want to choose from. Examples are such...

  • `ABX_ERR("message",value);
  • `ADD_TASK(name task); so on...

I would like to see all of these in a drop-down menu that I can choose from to insert into the file.

2 Answers 2

3

The full line completion (as suggested by @FDinoff) has several disadvantages: It considers all open buffers, and only works for completion at the beginning of a new line. A snippet plugin could do that, but has different syntax and additional, unneeded complexity.

The solution is a custom completion, for example the one implemented by my EntryComplete plugin. This plugin provides a highly configurable completion of lines found in designated files or buffers, triggered by a keyword in front of the cursor.

Sign up to request clarification or add additional context in comments.

Comments

2

Vim offers line completion (:h compl-whole-line)

Completing whole lines                                  compl-whole-line

                                                        i_CTRL-X_CTRL-L
CTRL-X CTRL-L           Search backwards for a line that starts with the
                        same characters as those in the current line before
                        the cursor.  Indent is ignored.  The matching line is
                        inserted in front of the cursor.
                        The 'complete' option is used to decide which buffers
                        are searched for a match.  Both loaded and unloaded
                        buffers are used.
        CTRL-L  or
        CTRL-P          Search backwards for next matching line.  This line
                        replaces the previous matching line.

        CTRL-N          Search forward for next matching line.  This line
                        replaces the previous matching line.

        CTRL-X CTRL-L   After expanding a line you can additionally get the
                        line next to it by typing CTRL-X CTRL-L again, unless
                        a double CTRL-X is used.  Only works for loaded
                        buffers.

If you use <C-X><C-L> you can complete lines in any open buffer. So just open the file you want to line complete from in the background and then use <C-X><C-L> to open a menu to select the lines that match start with the same characters as the current one.

2 Comments

Is there a way so specify a specific file to use? Otherwise it shows all the lines in all the windows I have open and is quite overwhelming.
@user3719021 I don't believe so.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.