Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set vim current working directory to the current project root or to the directory of the current file

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).

like image 627
foo Avatar asked Oct 21 '22 23:10

foo


1 Answers

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.

like image 70
abjuk Avatar answered Oct 24 '22 01:10

abjuk