Tip #370: always cd to the current file's directory
tip karma |
Rating 74/32, Viewed by 950
|
created: |
|
November 15, 2002 0:59 |
|
complexity: |
|
basic |
author: |
|
Dubhead |
|
as of Vim: |
|
6.0 |
When I have several or more files from various directories opened and am going to open another, I find it counter-intuitive to specify the file path from Vim's current directory. I think it's more natural to specify it from current file's directory (though this is not the traditional vi way). If you feel similarly, this simple tip may help you.
My solution is to have Vim always cd to the current file's directory. Put this in your .vimrc:
function AlwaysCD()
if bufname("") !~ "^ftp://";
lcd %:p:h
endif
endfunction
autocmd BufEnter * call AlwaysCD()
Note that Vim doesn't cd to a remote machine's directory. If you never open a file through network, just use this instead:
autocmd BufEnter * lcd %:p:h
<<Comment/UnComment visually selected text |
Encrypting a file within vim session and not leaving behind traces. >>
Additional Notes
|