Go to line number in a file using vim

Til

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