vimtricks.wiki Concise Vim tricks, one at a time.

How do I insert the entire current line into the command line without typing it?

Answer

<C-r><C-l>

Explanation

Pressing <C-r><C-l> on the command line inserts the full text of the current buffer line (the line the cursor is on when you pressed :) directly at the command-line cursor position. This saves you from re-typing or copy-pasting a line when you want to use it as part of an Ex command.

How it works

  • <C-r> — opens register insertion mode on the command line
  • <C-l> — inserts the current line (the line under the cursor in the buffer, verbatim)

The current line is inserted as a literal string; no register is involved. The cursor must have been on a specific line when : was pressed — that line is what gets inserted.

Example

Your buffer contains:

const DB_URL = "postgres://localhost:5432/mydb"

With the cursor on this line, press : then <C-r><C-l> to insert the full line:

:const DB_URL = "postgres://localhost:5432/mydb"▌

Now you can edit it into a substitution command:

:s/postgres:\/\/localhost:5432\/mydb/DB_URL/g

Tips

  • Combine with :g to match lines and insert them selectively: run :g/pattern/ to navigate, then : + <C-r><C-l> to grab the matched line
  • Also works in search mode: pressing / then <C-r><C-l> searches for the exact current line
  • The related <C-r><C-w> inserts the word under the cursor; <C-r><C-a> inserts the WORD (space-delimited); <C-r><C-l> inserts the whole line

Next

How do I make Vim reuse an existing window when jumping to a buffer instead of opening a new split?