Vim Go To End/Start of Line

Glory Kim
Glory KimSoftware Engineer, Loom
Published: January 31, 2024

Use the ESC key to enter normal mode in vim:

  • Press $ to move the cursor to the end of the line
  • Press g\_ to move the cursor to the last non-whitespace character

On the left is the result after typing $ to go to the end of the line, and on the right is the result after g\_ to go to the last non-whitespace character.

Insert at the end of a line with Vim

To edit the end of the line, you can press A to jump to the last character and switch to insert mode.

Go to the beginning of a line with Vim

In normal mode:

  • Press 0 to move the cursor to the start of the line
  • Press ^ or \_ to move to the first non-whitespace character in the line

To edit the beginning of the line, you can press I (capital i) to go to the first non-whitespace character and switch to insert mode.

Once you have navigated to the desired position, you can use other Vim commands such as:

  • j to move the cursor to the next line
  • x to delete the character under the cursor
  • dG to delete everything after the cursor

Note: The commands above are cursor-specific, meaning that the position of your cursor is essential and will affect the command. For those types of commands, navigating to either the end or the beginning of the line before executing those commands is helpful.

However, some commands, like those below, are line-specific and do not require the cursor to be at a specific position on the line:

  • o creates a new line below the current line and enters insert mode
  • O creates a new line above the current line and enters insert mode
  • J appends the next line next to the current line
  • dd deletes the current line
  • yy yanks (copy) the current line

To keep reading about navigating in Vim, check out these tips on going to the end of the file and copy and pasting.

Written by
Glory Kim
Glory KimSoftware Engineer, Loom
Filed under

Related articles


Go To End of File in Vim / Vi

Select and delete to the end of a file in Vim

Select all in Vim / Vi

Select all and copy, paste, or delete the contents

Copy & Paste in Vim / Vi

Copy (Yank), Paste (Put) and Cut (Delete) in Vim

Searching in Vim

Search forward, backward, case insensitive, and more

Show & Hide Line Numbers in Vim / Vi

Toggle absolute and relative line numbers

Undo & Redo in Vim / Vi

Keyboard shortcuts and summary of how Vim tracks changes

Go To Line In Vim

Variety of approaches to go to lines

Go To Top of File in Vim

Learn how to jump the top of the file in Vim, then navigate, search, highlight, and delete.

Vim Modes

Learn about seven of Vim’s modes

Vim / Vi Page Up and Down Controls

Quick reference for Vim's page up and down controls

How to delete lines in Vim / Vi

The best answer depends on which mode you use

Vim Find And Replace

You can use either the substitute command or the slash and dot method to search for patterns and replace with different values.