How to set the correct path for a file in VIM?

Whenever I press :pwd in vim, the command always returns the path C:\Windows\system32 , even if I am in the Python file from the desktop. So whenever I run :!python % , the command returns

 python: can't open file '\Users\myname': [Errno 2] No such file or directory. 

But if I set the path using the command :cd %:p:h and then run the same python command, the Python file will execute correctly. So basically I'm wondering how do I get vim to set the path for each file that I open correctly.

(i.e. if I in the file located on the desktop :pwd returns ~\Desktop\ , or if I in the file in the home directory :pwd returns C:\Users\MyName\ ).

+3
source share
1 answer

You can install autochdir :

 :set autochdir 

With this parameter, the current working directory will follow the edited file.

See :help 'autochdir' , and especially this note:

Note. If this option is enabled, some plugins may not work.

+6
source

All Articles