How can I (automatically, basically I shouldn't have anything to do apart from initial configuration) set vim cwd to the project root directory (if there's any) or to the current buffer directory (in an autochdir
fashion)?
Here is an example of a file path to expected cwd: ~/foo/bar/SOME_FILE
-> ~/foo
if there is a ~/foo/.git/
dir or a ~/foo/.hg/
dir otherwise ~/foo/bar/
I'm aware of airblade/vim-rooter but it doesn't quite work (e.g. it relies on specific file extensions, and I don't want this behavior).
You could use the vim-rooter plugin with an autocmd to trigger on all files, something like autocmd BufEnter * :Rooter
. That's probably the simplest way.
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