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:
To open file and go to function called killproc(), enter:
$ vim +/killproc functionsSample outputs:

Fig.02: Vi / vim open a file at a specific function / subroutine / procedure / method in source code
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 6 comments… read them below or add one }
To open file and go to line number 431, enter:
$ vim +546 functions
431 -> 546
And maybye there is the way to go to speciffied occurence of search term? Say, to the last? Or to 25th occurence?
If you want to pre-position at the x’th occurrence of “string”, you can use the command
vi +x/string file
thank-you @doug
Also note that you can use this functionality from within vim as well, e.g.:
:e +50 path_to_file
Thanks Aleksander its very easy and helpfull