I'm trying to cd into my project's git root from vim so that my Ctrl-P works properly. I often work in project's where I don't want Ctrl-P to look up to the git root so I have it set up to only look for the nearest folder with a .gitignore.
On the command line I can do something like cd $(git rev-parse --show-toplevel) but when I try the same thing in vim with :!cd $(git rev-parse --show-toplevel) it hides vim and just shows a blank output. I was told the ! in the vim command line would allow me to run bash commands. Am I missing something.
You can use backticks to run shell commands and pipe the output into Vim commands like :cd:
:cd %:h | cd `git rev-parse --show-toplevel`
This sets the current directory to the directory of the current file and then runs :cd with the git directory from the git rev-parse --show-toplevel command.
Alternatively, if you use fugitive.vim you can use the :Gcd command.
For more help see:
:h :cd
:h backtick-expansion
:h :bar
                        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