Vim Tip of the Day - File Explorer Navigation

posted @ Monday, May 05, 2008 9:17 PM

 

I don't know how I didn't come across this before, but when using the file explorer built into Vim, you can tell Vim to automatically switch the working directory to the current file you are editing.  Normally in Vim if you performed a ":cd c:\projects\blah" and subsequently navigated three folders deeper to edit a file (say “c:\projects\blah\foo\bar\foobar\fun.cs”), then choose to go back into the file explorer from your current location by issuing ":e .", the "c:\projects\blah" will be listed, not exactly where you might expect to be.  If you edit your _vimrc file and put the following command in when navigating the file explorer window, your current directory will automatically be set based on the file you are editing, and thus we would be dropped back into "c:\projects\blah\foo\bar\foobar").

autocmd BufEnter * lcd %:p:h 

Comments
Vincent Wang - 10/15/2008 1:22 AM
# re: Vim Tip of the Day - File Explorer Navigation
there is also a vim option 'autochdir' that can do this kind of work automatically.
Nick Parker - 10/15/2008 9:38 AM
# re: Vim Tip of the Day - File Explorer Navigation
Thanks for the tip Vincent.
Comments have been closed on this topic.