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

How do I force a Vim operator to act linewise even when the motion is normally characterwise?

Answer

dV{motion}

Explanation

In operator-pending mode — the brief state after typing an operator like d, c, or y but before entering the motion — you can prefix the motion with v, V, or <C-v> to force the operation to be characterwise, linewise, or blockwise regardless of the motion's default type. This gives precise control over how operators interact with motions that have the "wrong" type for your intent.

How it works

After typing an operator, insert a forced-motion modifier before the motion:

  • v — force characterwise (even if motion is linewise)
  • V — force linewise (even if motion is characterwise)
  • <C-v> — force blockwise

For example: dV/end<CR> searches for "end" and deletes all complete lines from the current line to the line containing the match — not just the characters up to "end".

Example

Given:

function foo() {
  doSomething();
  return 42;
}

With cursor on line 1, d/return<CR> normally deletes characterwise — from the cursor to just before "return" on line 3, splitting that line.

With dV/return<CR>, the delete is forced linewise — lines 1, 2, and 3 are deleted completely, leaving }.

Tips

  • yV{motion} yanks full lines using any motion, great for capturing complete lines for pasting
  • cV{motion} changes full lines — replaces entire source lines even with characterwise motions
  • dv{j} forces a linewise j motion (which usually deletes 2 lines) to be characterwise — useful for precise sub-line deletions
  • This is documented in Vim help as "forced motion" (:help forced-motion)

Next

How do I encode and decode JSON data in Vimscript for configuration and plugin development?