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.
Navigating around Vim
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
Software Engineer, Loom
Filed Under
Related Articles
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.
Vim Modes
Learn about seven of Vim’s modes
Go To Top of File in Vim
Learn how to jump the top of the file in Vim, then navigate, search, highlight, and delete.
Go To Line In Vim
Variety of approaches to go to lines
Vim / Vi Page Up and Down Controls
Quick reference for Vim's page up and down controls
Copy & Paste in Vim / Vi
Copy (Yank), Paste (Put) and Cut (Delete) in Vim
Undo & Redo in Vim / Vi
Keyboard shortcuts and summary of how Vim tracks changes
Show & Hide Line Numbers in Vim / Vi
Toggle absolute and relative line numbers
Select all in Vim / Vi
Select all and copy, paste, or delete the contents
Searching in Vim
Search forward, backward, case insensitive, and more
Go To End of File in Vim / Vi
Select and delete to the end of a file in Vim
How to delete lines in Vim / Vi
The best answer depends on which mode you use