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?
Asked
Active
Viewed 5,714 times
8
-
1This is not a duplicate of the linked question. – jdhao Apr 16 '19 at 03:38
1 Answers
18
: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
Alex Kroll
- 1,069
- 10
- 16
-
2
-
-
2Additionally, the setting
autochdircan be set in.vimrcto perform this action automatically. – PlasmaBinturong Apr 17 '20 at 14:30