Jun 5, 2022 2 min read

Move Cursor to Beginning or End of Line in Vim

Table of Contents

Vim is one of the most glorified text editors, and for a reason.

Every task that you can think of (except for typing the text) can be done with just a few keystrokes - without ever touching the mouse or trackpad.

Moving your cursor from the beginning or the end of the line is not a crucial task, but something you might be doing often enough for the repeated mashing of h or l keys to feel irritating, or worse, unproductive.

Thankfully, it can be easily done in Vim. Here's how.

  • Press the Esc key to be in the normal mode.
  • Press the 0 key to move the cursor to the beginning of the line (column 0)
  • Press $ key to move the cursor to the end of the line (last column).

Let's take a deeper look at how we can move the cursor from anywhere on the line to the beginning of the line or to the end of the line.

Move the cursor to the beginning of the line in Vim

In Vim, there are two ways you can move your cursor at the beginning of a line.

First, make sure that you are in Normal mode. Press the Esc key to make sure.

Then press either 0 (zero) key and it will move the cursor at the beginning of the line.

You can move the cursor to the beginning by pressing the ^ key as well.

Move the cursor to the end of the line in Vim

Vim has a straightforward way to move the cursor to the end of the line.

Again, you need to be in Normal mode to do this.

It does not matter in which column your cursor, only which line it is on. Then, press the $ key and it will move the cursor to the end of the line.

If the lines are wrapped, the cursor will go to the end of the wrapped line, not to the end of the column.

Conclusion

This article delves into the basics of cursor movement in Vim. Even trivial things like moving to the start or end of a line in Vim could be tiresome if you don't know the correct key combinations. But that's how Vim is.

On a related topic, you may like reading about moving to the beginning or end of a file in Vim.

If you are interested in learning more than just the Vim Basics, I highly recommend using this program by Jovica Ilic.

Mastering Vim Quickly - Jovica Ilic
Exiting Mastering Vim Quickly From WTF to OMG in no time
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Linux Handbook.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.