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

How do I copy a character from the line above or below while in insert mode?

Answer

<C-y> / <C-e>

Explanation

When typing in insert mode, you can pull individual characters from adjacent lines without leaving insert mode. <C-y> copies the character directly above the cursor, and <C-e> copies the character directly below. This is invaluable when you need to type something nearly identical to a neighboring line.

How it works

  • <C-y> — inserts the character from the same column on the line above the cursor
  • <C-e> — inserts the character from the same column on the line below the cursor
  • Each press copies one character; hold or press repeatedly to copy multiple characters in sequence
  • If the adjacent line is shorter than the current cursor column, nothing is inserted

Example

Suppose you are writing similar configuration lines:

server_host = "production.example.com"
server_port = "8443"

While on the second line in insert mode, pressing <C-y> repeatedly after typing server_ would pull characters from the line above one at a time: h, o, s, t... letting you reuse the structure without copy-pasting.

Tips

  • Particularly useful for aligned tabular data, similar variable names, or repetitive code patterns
  • Combine with regular typing — pull a few characters from above, then type the part that differs
  • Works alongside <C-n>/<C-p> word completion for different granularities of reuse

Next

How do I ignore whitespace changes when using Vim's diff mode?