Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change current path in Vim automatically?

Tags:

vim

macvim

When I type in terminal something like

mvim ./path/to/my/project

Vim opens this project directory, in my NERDTree I can see files, but when I try to run some CLI command, like

:!touch some/file/in/my/project

It occurs, that my current path is my users home directory

so if I want to create file in my project dir, I must type full path like

:!touch ./path/to/my/project/some/file/in/my/project/name

Is it possible somehow to automatically change dir after vim starts?

like image 313
Stanislav Mekhonoshin Avatar asked Dec 13 '12 16:12

Stanislav Mekhonoshin


Video Answer


1 Answers

I use this in my vimrc:

" Use %% on the command line to expand to the path of the current file
cabbr <expr> %% expand('%:p:h')
like image 72
Matthew Strawbridge Avatar answered Oct 06 '22 02:10

Matthew Strawbridge