I'm in the terminal, I cd <projectdirectory>. How can I open Vim positioned at the fn main() of this project.
I don't need a ready solution: ideas will be helpful. Could I potentially make Vim use racer to jump to a symbol automatically on start?
To open the file main.rs at the first line beginning with fn main, simply run:
$ vim main.rs +/'^fn main'
If you want every file named main.rs to automatically open to the first line beginning with fn main, you can add the following to your .vimrc file:
autocmd BufRead main.rs /^fn main
You can extend this to all files ending in .rs by changing main.rs to *.rs. However, if the file does not contain any matching lines, you will get an error message (Error detected while processing BufRead Auto commands for <filename>). The silent! command suppresses errors:
autocmd BufRead *.rs silent! /^fn main
This will search to fn main if it exists, but fail silently if it does not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With