Thursday, April 17, 2025

vim: Jump to specific character on a line

In Vim, to jump to a specific character on a line, you can use the following commands:

  • f{char} - Jump to the next occurrence of {char} on the current line
  • F{char} - Jump to the previous occurrence of {char} on the current line
  • t{char} - Jump until (one position before) the next occurrence of {char}
  • T{char} - Jump until (one position after) the previous occurrence of {char}

For your specific example of “go to first #”:

  • Type f# to jump to the first # character on the current line

Additional tips:

  • ; - Repeat the last f, F, t, or T command in the same direction
  • , - Repeat the last f, F, t, or T command in the opposite direction

These are extremely useful for quick navigation within a line without having to use arrow keys or other movement commands.

vim: Delete from current cursor position to end of the document

This was not obvious to me (or Claude.ai) - but search turned it up.

vG$d

Explanation

  • v enters visual mode
  • G moves to the last line of the document
  • $ moves to the end of that line
  • d deletes everything selected

This combination selects from the current cursor position all the way to the end of the document and then deletes it.