vi goto line

1. Context

Knowing the commonly used vi editor commands is absolute bliss. You can get your work done much faster with frequently used commands. The command to go to a specific line is one of those frequently used commands.

If the vi editor is not yet opened, use the vi command to open the editor. Then use one of the many options to go to a specific line. All the commands used here apply to the vim editor as well.



# vi to open the editor
vi

# vi FILE_PATH to open a file in vi editor
vi /home/profile/myfile.txt

# vim FILE_PATH to open a file in vim editor
vim /home/profile/myfile.txt

2. vi goto line

For line navigation, here are some scenarios:

  • go to a specific line
  • go to the first line of the file
  • go to the last line of the file

2.1 vi goto a specific line

First, press the Esc key to switch to the command mode. Then either use nG or :n to go to nth line.

# Switch to the command mode
Esc

# :line_number
:10 (to go to 10th line)

# Alternate command to use line_numberG
15G (to go to 15th line)

2.2 vi goto start of file

First, press the Esc key to switch to the command mode. Then press gg to go to the first line of the file.



# Switch to the command mode
Esc

# Go to the first line of the file
gg

2.3 vi goto end of file

First, press the Esc key to switch to the command mode. Then press the key G (Shift + G) to go to the last line of the file.

# Switch to the command mode
Esc

# Go to the last line of the file (Shift + G)
G

3. Conclusion

To work with the vi editor like a pro, refer to this article: Work With vi Editor Like a Pro.

vi goto line
Be The First

Join our list to get instant access to new articles and weekly newsletter.

Tagged on:                 
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x