"C:\temp\test.txt". I issue the command
:saveas test2.txt
The file is saved as C:\test2.txt, hHow can I make it be saved
as C:\temp\test2.txt?
My current solution is to define my own command (all one line)
command! -nargs=1 SaveasSamePath exe "saveas " . expand("%:p:h") .
"/" . expand("<args>")
I would like it just to work with :saveas though. I have tried using
the BufFilePre event to move to the right directory first.
au BufFilePre * cd %:p:h | registers | echo getcwd()
This changes the current working directory but the file still ends up
in the old working directory. I think this is because the full name
"C:\test2.txt" is stored right after the command is issued before
BufFilePre
occurs. The registers part of my command shows it in the alternate-
file
register. If I could change that register at that point I guess it
would work,
but it is a read-only register.
(Another problem is that BufFilePre triggers for :saveas and :file
commands, I
don't use :file myself but I don't want to break any plugins that
might use it
so ideally my solution would check, was this event caused by :saveas?
I don't
know how to check that. I thought of checking register ": (most
recently
executed command) for "sav", but it only gets set once the command is
complete.)
One solution would be to move the file once it has been saved but that
seems
inelegant especially if moving between drives.
I know there are ways of changing the working directory whenever you
switch to
a buffer but I'd prefer not to do that. If I could get BufFilePre
working, I would
use BufFilePost to move back to the original working directory
afterwards.
Any ideas?
regards,
Geoff
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment