4

This question already has an answer here:

Sometimes I use Command-T to browse files. When I find the file I needed, I would like to switch the current working directory to the opened file's directory. How can I do this?

marked as duplicate by Martin Tournoij Jun 23 '15 at 18:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • This is not a duplicate of the linked question. – jdhao Apr 16 at 3:38
10

:cd %:h

Explain:
:cd change directory Vim command
% - full path to current file
%:h - full path to current file without filename itself.

See :help expand and :help :cd for more information

  • 1
    A better pointer: :help cmdline-special – lcd047 Jun 23 '15 at 17:49
  • @lcd047 yes! Agree! Very useful! – Alex Kroll Jun 23 '15 at 17:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.