Reputation: 5663
Recently my vim will change current directory no matter what I do. I'm using spf13 distribution and when I am in a rails app root directory and did vi
, my pwd
will be correctly in app root directory. But once I open some file, any file, it will change the pwd
to abosolute/path/to/myrailsapp/app/assets/stylesheets
,
When I don't have let g:spf13_no_autochdir = 1
in my .vimrc, vim will change the pwd
to current file directory; When I do, it will change to the stylesheet directory whenever I open a file.
I'm also using rails.vim
installed. Here is the related code inside my .vimrc
if !exists('g:spf13_no_autochdir')
autocmd BufEnter * if bufname("") !~ "^\[A-Za-z0-9\]*://" | lcd %:p:h | endif
" Always switch to the current file directory
endif
UPDATE:
What I want: the pwd
always stay in absolute/path/to/myrailsapp/
, no changing to the stylesheet
directory automatically whenever I open a file.
Upvotes: 1
Views: 2539
Reputation: 61
I solved this according to Ben's second answer.
spf13 loads configuration files in order as follows.
if !exists('g:spf13_no_autochdir')
check is done at (7), so let g:spf13_no_autochdir = 1
should be loaded before that.
I put it in .vimrc.before.local, and it works as expected.
Upvotes: 1
Reputation: 8905
Actually I just found and had a look at the plugin. I assume this is it:
https://github.com/spf13/spf13-vim/blob/3.0/.vimrc
Around line 75 you can see:
" Most prefer to automatically switch to the current file directory when
" a new buffer is opened; to prevent this behavior, add the following to
" your .vimrc.before.local file:
" let g:spf13_no_autochdir = 1
So just add that last line (without the comment-marker quote) to your .vimrc and you'll get rid of the automated directory change.
I note that neither method in my other answer would have worked, because the plugin author for whatever reason decided not to use the built-in option, and also not to put their autocmd in a group. Naughty, naughty!
Upvotes: 1
Reputation: 8905
There are two ways this could be happening.
The most likely, is that this "spf13" configuration includes set autochdir
. To find out whether this is the case, start up Vim normally, and type :verbose set autochdir?
and press Enter. This should tell you IF autochdir is set and WHICH FILE set it to that value.
If autochdir is set, then you only need to set up a VimEnter autocmd, or stick a file in ~/.vim/after/plugin, to turn it off again after spf13 loads.
If autochdir is NOT set, then probably an autocmd is setting your directory for you. If there is a plugin option in SPF13 to turn it off, then do that. If not, you'll need to find where in the plugin the directory is getting changed. If you're lucky, the autocmd will be in an augroup by itself, and you can then remove that autocmd with :au! GroupName
. This command can be in the same places; a VimEnter autocmd, or a file in ~/.vim/after/plugin.
Upvotes: 0