Monday, April 23, 2012

VI / VIM: Open File And Go To Specific Function or Line Number

How do I open a text file using VIM or VI and go to specific line? How do I open a file using vim and go to specific function() in my source code?

The vi / vim text editor supports running any : command using the following syntax:
 
vi +commandHere fileName
vi +/searchTermHere fileName
vi +/LineNumberHere fileName
vim +/LineNumberHere fileName
 
To open file and go to line number 546, enter:
$ vim +546 functions
Sample outputs:
Vi / Vim open a file at a specific line number
Fig.01: Vi / Vim open a file at a specific line number

To open file and go to function called killproc(), enter:
$ vim +/killproc functions
Sample outputs:
Vi / vim open a file at a specific function / subroutine / procedure / method in source code
Fig.02: Vi / vim open a file at a specific function / subroutine / procedure / method in source code

No comments:

Post a Comment