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

How do I insert the full WORD under the cursor (including slashes and dots) into the command line?

Answer

<C-r><C-a>

Explanation

When you are in command-line mode, <C-r><C-w> inserts the word under the cursor (alphanumeric and _ only). <C-r><C-a> inserts the entire WORD — the contiguous sequence of non-whitespace characters — which includes file paths, URLs, dotted identifiers, and any other punctuation-heavy tokens. This saves you from manually typing or escaping complex strings.

How it works

  • In command-line mode (after :, /, ?, or !), <C-r> opens a register-paste prompt
  • <C-w> pastes the word under the cursor (defined by iskeyword)
  • <C-a> pastes the WORD under the cursor (everything up to the next whitespace)
  • The WORD is inserted literally at the cursor position in the command line

Example

With the cursor anywhere on /usr/local/bin/nvim in the buffer, enter command-line mode and press <C-r><C-a> to instantly get:

:/usr/local/bin/nvim

Useful for quickly opening, substituting, or grepping the exact token under the cursor without retyping it.

Tips

  • <C-r><C-w> is useful for simple identifiers; reach for <C-r><C-a> when the token contains /, ., -, or :
  • Works in search mode (/) too: position on a file extension like .tsx and press <C-r><C-a> to search for it
  • <C-r><C-f> inserts the file name under the cursor (same as gf would open)

Next

How do I match a pattern only when it is preceded or followed by another pattern, without including that context in the match?