Loading ...
Sorry, an error occurred while loading the content.

136976Re: expand('%:p') doesn't work properly when opening a new file in a non-existing directory?

Expand Messages
  • Tony Mechelynck
    Mar 29, 2013
      On 30/03/13 03:50, hong@... 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')
      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.)

      Best regards,
      Machine-Independent, adj.:
      Does not run on any existing machine.

      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@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Show all 4 messages in this topic