Last Updated: February 25, 2016
·
1.302K
· spf13

Change Working Directory to that of current file

A lot of features in vim work off of the working directory. Here's a quick way to change the working directory to that of the file you are in.

" Change Working Directory to that of the current file
cmap cwd lcd %:p:h
cmap cd. lcd %:p:h

There are two alternative keymappings here.

I prefer the latter, but there's no harm of having both in your .vimrc file.

... or simply install spf13-vim, a popular vim configuration & distribution that stays true to the feel of vim while providing modern features like a plugin management system, autocomplete, tags and tons more.