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 typingset number
. Now at least you can see the line numbers while you arrow down… (To remove line numbers, do:
and typeset 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
- hit
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
Top comments (2)
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!And I did not know about the option of opening on the line! Thanks for sharing!