Omnicomplete Entire Lines in Vim

27 Dec 2010

Autocompleting entire lines in Vim is a handy way to quickly write a python import statement. Insert a new line, type from (and maybe a few chars of the beginning of your import statement), and Ctrl-x Ctrl-l away!

Via vimdocs:

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.

LOVE being able to autocomplete an entire line in Vim!

Let's talk

I'm one of the founders of Venmo. If you liked this essay/experiment -- or didn't -- @ me.