On Aug 22, 10:20 am, lessthanideal <[email protected]> wrote: > > A recent unrelated thread showed me what's obviously a more correct > way to > redefine :saveas than my attempts, i.e. remapping :sav to call my > custom > command. I can't account for not spotting that before (especially > since I > was already mapping F7 to call it ): Anyway, now I have > > "All on one line > command! -nargs=1 SaveasSamePath exe "sav " . expand("%:p:h") . "/" . > expand("<args>") > > "Remap so I get my command > nnoremap :sav :SaveasSamePath > > "... and so I can still get the original if I need it by typing it in > full > nnoremap :saveas :saveas >
I'd suggest a command-line abbreviation rather than a normal-mode mapping to accomplish this: > Hopefully this won't cause problems even for plugins that assume no > mappings > and issue the command ":sav" themselves. I haven't been able to make > it > go wrong myself in defined commands (defining more execute commands to > call "sav" > works as expected and calls :saveas). > If your mappings screw up a plugin, that's the plugin's fault. They ought to be using commands such as :normal! (with the '!') to avoid user mappings if they assume any behavior at all. > The original reason I didn't want to change the working directory > whenever I > switch to a buffer was because 'autochdir' seemed to cause problems, > and also, > the help makes it sound (to me) like a very non-standard option. That > was a > couple of years ago when I looked at this. (This saveas problem > doesn't trip > me up very often, which is why I can't just remember %:p:h) I did > more > recently find > > http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file > > and my impression was the methods of doing this still might cause > problems in > some situations; since I don't particularly want to change directory > apart from > to solve my saveas problem, it seemed better to avoid doing so. But, > if this > remapping doesn't work out I'll probably look at it again. > For what it's worth, I've been running with either the autocmd or the 'autochdir' option active in my .vimrc for four years now with almost no trouble whatsoever. There was a bug a few years ago in netrw concerning the autochdir option, and there was a bug in the --remote commands where 'autochdir' just didn't work until (I think) 7.3, and there are (or were) some troubles with sessions (:mksession sessions) when 'autochdir' was set and there were special plugin buffers around. Other than that, no problems here. -- 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
