chatgpt-4o-latest-20250326· OpenAI
LMArena Human Preference 140K
in vim, alternatives to $ to move to end of line
- User
in vim, alternatives to $ to move to end of line
- 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
$-
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_
-
^(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$vsd^.
-
CTRL+othen$(in insert mode)- If you're in insert mode, you can temporarily return to normal mode with
CTRL-o, then use$.
- If you're in insert mode, you can temporarily return to normal mode with
-
Using
Endkey- If your keyboard or terminal setup supports it, pressing the
Endkey also moves the cursor to the end of the line.
- If your keyboard or terminal setup supports it, pressing the
-
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), ort;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.
- Use
🛠️ 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
Command Moves 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.)!
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.