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?
1This is not a duplicate of the linked question.– jdhaoApr 16, 2019 at 3:38
:cd change directory Vim command
% - full path to current file
%:h - full path to current file without filename itself.
:help expand and
:help :cd for more information
2A better pointer:
:help cmdline-special– lcd047Jun 23, 2015 at 17:49
@lcd047 yes! Agree! Very useful! Jun 23, 2015 at 17:57
1Additionally, the setting
autochdircan be set in
.vimrcto perform this action automatically. Apr 17, 2020 at 14:30