Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

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

share|improve this answer
    
No, that file is also place in C:\Windows\system32 and not in ~\myprojects\testproject\todo.txt. –  Jonas Dec 8 '11 at 11:58
    
Sorry, I misread your question. I will come back with a proper answer soon. –  ReyCharles Dec 8 '11 at 12:01
    
How about now? Does this answer your question? –  ReyCharles Dec 8 '11 at 12:10
add comment

I have the following in my vimrc:

map <Leader>e :e <C-R>=expand("%:p:h") . "/" <CR>

This opens the command line, enters the 'e' command and pre-populates the file argument with the path to the file in the currently active buffer. The key is mapped to the backslash key by default.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.