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 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 case3842 <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> 🙂
Thank you for reading!
I'd love to hear your thoughts — let's keep the conversation going on X: @Flavia_SBastos