Windows – How to open a new file in the current directory with gvim on Windows

gvimhome-directoryvimwindows

If I'm working on a file located on e.g. ~\myprojects\testproject\hello.txt and then want to open a new file in the same directory e.g. todo.txt (located on ~\myprojects\testproject\todo.txt), how can I do that efficiently with gvim on Windows?

Today I have to type this command, maybe using tab-completion for the paths:

:e ~\myprojects\testproject\todo.txt

Is there any shorter command e.g:

:e .\todo.txt

in gvim on Windows?

If I use .\todo.txt, that file will be located on C:\Windows\system32, that's not even my home directory. Is there any setting to specify my home directory as default instead? or any other diectory?

Best Answer

The following should work, provided your current dir is where the file is:

:e todo.txt

For the second question I don't know a good answer. You can of course do

:cd ~

every time you start up, or you could edit your vimrc to do that. It's a hack and not a good solution.

There's also 'autochdir' if you want to cd to the file every time. I found it here: http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file

In your vimrc you would put in this line:

set autochdir

Edit2: add answer to second question