On Friday, March 29, 2013 9:14:17 PM UTC-7, Tony Mechelynck wrote:
>> On 30/03/13 03:50, hong@topbug.net wrote:
>>
>>> Hi All,
>>
>>>
>>
>>> According to the document of expand, "expand('%:p')" should be able to give full path of current buffer. This works properly when use vim to open an existing file or create a new file in an existing directory. But If I execute this command:
>>
>>>
>>
>>> gvim a/a.c
>>
>>>
>>
>>> where a is a non-existing directory. Then I run ":echo expand('%:p')", it gives 'a/a.c', which is not what I expected. Other modifiers just work as expected except '%:r'.
>>
>>>
>>
>>> Anyone have any ideas?
>>
>>>
>>
>>> Thanks!
>>
>>> Hong
>>
>>>
>>
>>
>>
>> In this case, trying to write the file will answer "a/a.c: E212 Cannot
>>
>> open file for writing", showing that there is *no* path to the file. But
>>
>> after creating a subdirectory ./a in the current directory,
>>
>> expand('%:p') gets a sensible value, and the write (if attempted) succeeds.
>>
>>
>>
>> On Unix you might try
>>
>> :exe '!mkdir -pv' expand('%:h')
>>
>> :w
>>
>> if you really want to save the file under that name. (Of course it will
>>
>> fail if you don't have the necessary directory-creation permissions.)
>>
>>
Hi Tony,
Thanks for your reply.
I have noticed that I can not write to disk if I create a new file in a
non-existing directory; what I am concerning is the unexpected behavior
of `expand('%:p')`. I am currently encountering an issue in my plugin: I
call `expand('%:p')` to obtain the full path, but in the given case
above, I would get a truncated path. So I think this behavior should not
be expected. Do you think so?
Thanks,
Hong
--
--
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
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment