• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Go To Line In Vim

Thumbnail for Preston Tunnell WilsonPreston Tunnell Wilson

Preston Tunnell Wilson

Senior Software Engineer, InStride Health

Published: 1/31/2024

About Terminus

The Short Answer

To go to a specific line number, enter the line number in Command-line Mode (:<line number>) or the line number and G (<line number>G) in Normal Mode.

Thumbnail for

For more information on how to switch between the different Vim modes, check out our brief introduction to the different Vim modes

Opening a File in Vim at a Specific Line Number

If you know ahead of time which line you want to go to, for example when you need to edit a failing test, you can include the line number when you start Vim with vim +<line number> <filename>:

Thumbnail for

Note that this syntax works for any Vim command in general: if you want to execute a command upon Vim startup, you can include it after +.

We've covered going to a specific line by using the line number directly in Command-line mode and Normal mode, but we can also navigate to a specific line relative to our current line (our article on moving up and down in Vim covers this briefly). For smaller vertical jumps, you can probably judge the amount to jump by eye, and you will get better and better at estimating larger and larger jumps the more you use Vim. However, Vim itself can show you how many lines to jump up or down with relative line numbers. Turn them on with set relativenumber in Command-line mode, then use the number in the gutter of the file to jump to a line relative to your current placement.

Thumbnail for

Showing line numbers is very helpful when editing in general. For more information on showing line numbers, check out our article on showing and hiding line numbers in Vim

Going to a Line that Contains Searched-For Text

To navigate to a line that contains a specific word or text, you can use the search pattern syntax /<pattern>, which can also be used as a Vim startup command. See our article on finding and replacing text in Vim for more detail.

Thumbnail for

Finally, you can also enable the mouse in Vim and go to a specific line (and column) by clicking on it. You can enable the mouse for certain Vim modes or in all modes (which is what I did below with set mouse=a):

Thumbnail for

Written by

Thumbnail for Preston Tunnell WilsonPreston Tunnell Wilson

Preston Tunnell Wilson

Senior Software Engineer, InStride Health

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.

VimVi
Thumbnail for Glory KimGlory Kim

Vim Modes

Learn about seven of Vim’s modes

VimVi
Thumbnail for Razvan LudosanuRazvan Ludosanu

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
Thumbnail for Glory KimGlory Kim

Vim / Vi Page Up and Down Controls

Quick reference for Vim's page up and down controls

VimVi
Thumbnail for Glory KimGlory Kim

Vim Go To End/Start of Line

Go to the end or beginning of a line in Vim

Vim
Thumbnail for Glory KimGlory Kim

Copy & Paste in Vim / Vi

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

VimVi
Thumbnail for Jessica WangJessica Wang

Undo & Redo in Vim / Vi

Keyboard shortcuts and summary of how Vim tracks changes

VimVi
Thumbnail for Jessica WangJessica Wang

Show & Hide Line Numbers in Vim / Vi

Toggle absolute and relative line numbers

VimVi
Thumbnail for Amber ChenAmber Chen

Select all in Vim / Vi

Select all and copy, paste, or delete the contents

VimVi
Thumbnail for Glory KimGlory Kim

Searching in Vim

Search forward, backward, case insensitive, and more

VimVi
Thumbnail for Neeran GulNeeran Gul

Go To End of File in Vim / Vi

Select and delete to the end of a file in Vim

VimVi
Thumbnail for Preston Tunnell WilsonPreston Tunnell Wilson

How to delete lines in Vim / Vi

The best answer depends on which mode you use

VimVi
Thumbnail for Andrew CarlsonAndrew Carlson

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Request demo
Thumbnail for null