Terminus
Vim Go To End/Start of Line

Vim Go To End/Start of Line

Use the [.inline-code]ESC[.inline-code] key to enter normal mode in vim:

  • Press [.inline-code]$[.inline-code] to move the cursor to the end of the line
  • Press [.inline-code]g_[.inline-code] to move the cursor to the last non-whitespace character

On the left is the result after typing [.inline-code]$[.inline-code] to go to the end of the line, and on the right is the result after [.inline-code]g_[.inline-code] to go to the last non-whitespace character.

[#insert-at-end-line]Insert at the end of a line with Vim[#insert-at-end-line]

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

[#go-to-line-beg]Go to the beginning of a line with Vim[#go-to-line-beg]

In normal mode:

  • Press [.inline-code]0[.inline-code] to move the cursor to the start of the line
  • Press [.inline-code]^[.inline-code] or [.inline-code]_[.inline-code] to move to the first non-whitespace character in the line

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

[#navigating]Navigating around Vim[#navigating]

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

  • [.inline-code]j[.inline-code] to move the cursor to the next line
  • [.inline-code]x[.inline-code] to delete the character under the cursor
  • [.inline-code]dG[.inline-code] 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:

  • [.inline-code]o[.inline-code] creates a new line below the current line and enters insert mode
  • [.inline-code]O[.inline-code] creates a new line above the current line and enters insert mode
  • [.inline-code]J[.inline-code] appends the next line next to the current line
  • [.inline-code]dd[.inline-code] deletes the current line
  • [.inline-code]yy[.inline-code] 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.