Tip 116Autocomplete Entire Lines

In all of the examples so far, we’ve looked at completing words, but Vim can also autocomplete entire lines.

Line-wise autocompletion is triggered by running <C-x><C-l> (see compl-whole-line). Suppose that we started off with this snippet:

 .top {
  background-color: #ef66ef; }
 .bottom {

We want to duplicate the second line and place it at the end of the file. Here’s how this can be done using whole-line autocompletion:

KeystrokesBuffer Contents

{start}

 .top {
  background-color: #ef66ef; }
 .bottom {

oba

 .top {
  background-color: #ef66ef; }
 .bottom {
  ba

<C-x><C-l><Esc>

 .top {
  background-color: #ef66ef; }
 .bottom {
  background-color: #ef66ef; }

The same files ...

Get Practical Vim, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.