How to go to the end of a line in Vim
In Normal mode, press $ to go to the end of the line and 0 to go to the beginning. ^ goes to the first character after the indent. A and I go to the end or start and let you type.
Fix the line ends
Three small fixes, each at one end of a line: a doubled semicolon, a missing one, and a missing return at the start of the indented code.
This editor needs a keyboard. Read on, and play it at your computer.
| Keys | Goes to |
|---|---|
| $ | the last character of the line |
| 0 | the first column, before any indent |
| ^ | the first non-blank character, after the indent |
| g_ | the last non-blank character (skips trailing spaces) |
| A | the end of the line, in Insert mode |
| I | the first non-blank character, in Insert mode |
| gI | the first column, in Insert mode |
| 3$ | the end of the line two below (a count moves down count - 1 lines) |
| D / C | deletes / changes from the cursor to the end of the line (same as d$ / c$) |
| d0 / d^ | deletes from the cursor back to the start / to the first non-blank |
0 or ^?
In code most lines are indented, and the two differ by exactly that indent. 0 goes to column one, before the spaces; ^ skips them and lands on the first real character, which is usually where you want to be. I works like ^ followed by i: it starts typing in front of the code, not in front of the indent. The Home and End keys also work in Vim, in Normal and Insert mode, but 0, ^ and $ are on the home row and combine with operators.
Motions, not just jumps
All three work after an operator: d$ deletes to the end of the line, y^ copies from the first character to the cursor, c0 changes everything before the cursor. $ in Visual mode takes the line break too, so v$d joins the next line onto this one; g_ stops on the last character, so vg_y copies the rest of the line without it.