Skip to content
TheChatArchiveThe Chat Archive
chatgpt-4o-latest-20250326· OpenAIHugging Face LMArena Human Preference 140K

in vim, alternatives to $ to move to end of line

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-sonnet-4-20250514’s answer.
  1. User

    in vim, alternatives to $ to move to end of line

  2. Assistant

    In Vim, the $ command is commonly used to move the cursor to the end of a line. However, there are several alternative ways to achieve the same or similar effect:


    🔁 Basic Alternatives to $

    1. g_

      • Moves the cursor to the last non-blank character of the line.
      • Useful if your line ends with spaces or tabs and you want to skip them.
      • Example:
        :normal g_
        
    2. ^ (Caret)

      • Moves to the first non-blank character of the line.
      • This is not the end of the line, but works as a contrast to $.
      • Useful in combination with motion ranges like d$ vs d^.
    3. CTRL+o then $ (in insert mode)

      • If you're in insert mode, you can temporarily return to normal mode with CTRL-o, then use $.
    4. Using End key

      • If your keyboard or terminal setup supports it, pressing the End key also moves the cursor to the end of the line.
    5. f<char>, F<char>, t<char>, T<char>

      • These move the cursor to specific characters in the line; if you know the last non-whitespace character, you could jump with these.
      • Example: F} jumps to the last } on the line (goes backwards), or t; if your line ends with a semicolon.

    🏃‍♀️ In Visual Mode

    • If you're selecting to the end of the line (for yanking or deleting):

      • Use v$ — select from cursor to physical end (includes trailing whitespace).
      • Use vG — select until end of file.
      • Use vg_ — select to the last non-blank character.

    🛠️ In Mappings or Scripts

    If you're writing mappings or Vim scripts and want more precise control:

    normal! g_
    

    or

    call cursor(line('.'), col('$'))
    

    This script version moves the cursor to the column number at the end of the current line.


    ⌨️ Summary of Alternatives

    CommandMoves Cursor To
    $Physical end of the line
    g_Last non-blank character of the line
    EndEnd of the line (depends on terminal)
    f<char>First occurrence of <char> (forward)
    F<char>First occurrence of <char> (backward)
    t<char>Just before <char> (forward)
    T<char>Just after <char> (backward)

    Let me know if you want motion-based alternatives (like editing, deleting to the end of the line, etc.)!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.