DEV Community

Flávia Bastos
Flávia Bastos

Posted on • Originally published at flaviabastos.ca on

3

Go to line number in a file using vim

You want to see line 3842 of file called my_super_long_file.py and you can only access that file using vim. You open the file and to your dismay, by default, vim doesn’t display line numbers. Here are your options:

  • Arrow down and hope you find that line before retirement
  • Display the line numbers by hitting : and typing set number. Now at least you can see the line numbers while you arrow down… (To remove line numbers, do: and type set nonumber)
  • Go directly to that line by using one of the following options:
    • hit : and type the line number and enter, in this case :3842 enter
    • type the line number and hit SHIFT+g

Note: if you hit SHIFT+g without typing the line number, you go to the end of the file.

BONUS: You can accomplish the same thing in VSCode by hitting CTRL+g, typing the line number and enter 🙂

The post _Go to line number in a file using vim was originally published at _flaviabastos.ca

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (2)

Collapse
 
jvanz profile image
José Guilherme Vanz

Nice tips! I did not know the SHIFT+g one. :)
Another option I used a lot is the vim my_super_long_file.py +3842. Thus, vim open the file and jump directly to line I've specified in the command line. Thanks for you article!

Collapse
 
flaviabastos profile image
Flávia Bastos

And I did not know about the option of opening on the line! Thanks for sharing!