vim: change current directory

I like using the excellent FuzzyFinder plugin for vim. It’s usefulness is heavily dependent on keeping the current directory what I want, though, because otherwise I could do a lot of drilling. I found that I needed a better way of changing directories. What I wanted most of the time was a way to change to the directory of the current file.

I found this while searching for a way to switch to the current directory. I’m not sure whether I picked the same mapping as the author.

map ,C :cd %:p:h<CR>

Admittedly, I’m not sure where the :p:h comes from, but it works well. A couple of months after I found this, I made a second mapping for lcd. Additionally, because I want to lcd to the current directory more often, I made lcd the more convenient remapping.

map ,c :lcd %:p:h<CR>
map ,C :cd %:p:h<CR>

A word about lcd: it changes the directory for the current window, not the current buffer. This sounded obvious to me after I figured it out, but prior to then I thought it was tied to the buffer it’s invoked on and buffers spawned from that buffer.

Another thing I’d like to learn is how to change to the global directory when a local directory is set (or remove the current local directory).

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.