tags:

views:

249

answers:

1

I have an auto command triggered off BufEnter in my .vimrc to cd into the current buffer directory (very useful)

au   BufEnter *   execute ":lcd " . expand("%:p:h")

The problem is this fails on FTP files (as you might expect). The real problem is the error message telling me it has failed. Is there any way to suppress the error message, or alternatively "cd" into the current directory for FTP files as well (to make opening other files in the directory easier).

Just making the error message go away would be very helpful though! I've tried various experiments with the :silent command, but either it's not working for this command, or I didn't put it in the correct place.

+2  A: 

Did you try:

au BufEnter * execute ":silent! lcd " . expand("%:p:h")

:silent! is supposed to skip errors as well as messages.

As a side note, also have a look at :h 'autochdir' which does something similar to your autocommand. (However see :h netrw-incompatible for caveats.)

Brian Carper
Thanks - that is exactly what I wanted. I had a look at that autochdir variable, and I think I'll stick with the autocmd, as I know it works with all the plugins I want.
Greg Reynolds