" CDC = Change to Directory of Current file The following allows you to enter :CDC to change directory (it also displays the new directory): If you prefer, use a command instead of a mapping. To print the directory after changing, so you know where you ended up.
The command below maps your leader key followed by cd to do that. Rather than automatically change the working directory, you can use a mapping or a user command to easily change directory to the file being edited.
This autocmd changes the window-local current directory to be the same as the directory of the current file. Sometimes, as an alternative to setting autochdir, the following command gives better results: That's it! Unfortunately, when this option is set some plugins may not work correctly if they make assumptions about the current directory. To achieve this, put the following in your vimrc: Sometimes it is helpful if your working directory is always the same as the file you are editing.
#Windows gvim list directory contents full#
In these commands, % gives the name of the current file, %:p gives its full path, and %:p:h gives its directory (the "head" of the full path).Īutomatically change the current directory You can also change the directory only for the current window (each window has a local current directory that can be different from Vim's global current directory):
#Windows gvim list directory contents windows#
To change to the directory of the currently open file (this sets the current directory for all windows in Vim): The present working directory can be displayed in Vim with: