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

How to write a literally '%' in ex

Expand Messages
  • frakel
    Hi all, I am struggling with the correct syntax for starting the browser with the file in the current buffer through the DOS commandline: I have played a lot
    Message 1 of 8 , Apr 3, 2008
    • 0 Attachment
      Hi all,

      I am struggling with the correct syntax for starting the browser with
      the file in the current buffer through the DOS commandline:
      I have played a lot around but get no working solution, my best one
      looks like this (in my _vimrc mapped to <F8>):

      :exe '! "'.mybrowser.'" file:///'.substitute(expand("%:p"),' ',"\
      %20","g")

      The problem is the substitution of the blanks in path of the file
      which have to be replaced with '%20' for html-files, but vim always
      expands '%' '\%' and whatever to the filename...

      Has anyone an idea how to solve this conflict?

      Thanks a lot,
      franz
      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Tony Mechelynck
      ... In a double-quoted string, backslashes are used as escapes. Try using ... , %20 , g ) Thus the :! command should see the backslash before the percent
      Message 2 of 8 , Apr 3, 2008
      • 0 Attachment
        frakel wrote:
        > Hi all,
        >
        > I am struggling with the correct syntax for starting the browser with
        > the file in the current buffer through the DOS commandline:
        > I have played a lot around but get no working solution, my best one
        > looks like this (in my _vimrc mapped to<F8>):
        >
        > :exe '! "'.mybrowser.'" file:///'.substitute(expand("%:p"),' ',"\
        > %20","g")
        >
        > The problem is the substitution of the blanks in path of the file
        > which have to be replaced with '%20' for html-files, but vim always
        > expands '%' '\%' and whatever to the filename...
        >
        > Has anyone an idea how to solve this conflict?
        >
        > Thanks a lot,
        > franz

        In a double-quoted string, backslashes are used as escapes. Try using
        single quotes instead:

        :exe '! "' . mybrowser . '" file:///' . substitute(expand('%:p'),'
        ','\%20','g')

        Thus the :! command should see the backslash before the percent sign,
        unlike in your command above. I hope it will pass \% as % to the
        browser, but I haven't tested it.


        Best regards,
        Tony.
        --
        ARTHUR: A scratch? Your arm's off!
        BLACK KNIGHT: No, it isn't.
        ARTHUR: Well, what's that then?
        BLACK KNIGHT: I've had worse.
        The Quest for the Holy Grail (Monty
        Python)

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Franz Kelnreiter
        Thank you for your hint but this does expand the filename alike. I tryed every kind of % % % % , ex substitutes all these with the filename. So how to
        Message 3 of 8 , Apr 3, 2008
        • 0 Attachment
          Thank you for your hint but this does expand the filename alike.

          I tryed every kind of "%" "\%" '%' '\%', ex substitutes all these with
          the filename. So how to write '%20' ??

          Franz

          2008/4/3, Tony Mechelynck <antoine.mechelynck@...>:
          >
          > frakel wrote:
          > > Hi all,
          > >
          > > I am struggling with the correct syntax for starting the browser with
          > > the file in the current buffer through the DOS commandline:
          > > I have played a lot around but get no working solution, my best one
          > > looks like this (in my _vimrc mapped to<F8>):
          > >
          > > :exe '! "'.mybrowser.'" file:///'.substitute(expand("%:p"),' ',"\
          > > %20","g")
          > >
          > > The problem is the substitution of the blanks in path of the file
          > > which have to be replaced with '%20' for html-files, but vim always
          > > expands '%' '\%' and whatever to the filename...
          > >
          > > Has anyone an idea how to solve this conflict?
          > >
          > > Thanks a lot,
          > > franz
          >
          >
          > In a double-quoted string, backslashes are used as escapes. Try using
          > single quotes instead:
          >
          >
          > :exe '! "' . mybrowser . '" file:///' . substitute(expand('%:p'),'
          >
          > ','\%20','g')
          >
          > Thus the :! command should see the backslash before the percent sign,
          > unlike in your command above. I hope it will pass \% as % to the
          > browser, but I haven't tested it.
          >
          >
          > Best regards,
          > Tony.
          >
          > --
          > ARTHUR: A scratch? Your arm's off!
          > BLACK KNIGHT: No, it isn't.
          > ARTHUR: Well, what's that then?
          > BLACK KNIGHT: I've had worse.
          > The Quest for the Holy Grail (Monty
          > Python)
          >
          >
          > >
          >

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Christian Brabandt
          ... I think something is eating your backslash. So I would add additional 2 ... regards, Christian --~--~---------~--~----~------------~-------~--~----~ You
          Message 4 of 8 , Apr 3, 2008
          • 0 Attachment
            Am Do, 3.04.2008, 10:38, schrieb frakel:
            > I am struggling with the correct syntax for starting the browser with
            > the file in the current buffer through the DOS commandline:
            > I have played a lot around but get no working solution, my best one
            > looks like this (in my _vimrc mapped to <F8>):
            >
            > :exe '! "'.mybrowser.'" file:///'.substitute(expand("%:p"),' ',"\
            > %20","g")
            >
            > The problem is the substitution of the blanks in path of the file
            > which have to be replaced with '%20' for html-files, but vim always
            > expands '%' '\%' and whatever to the filename...
            >
            > Has anyone an idea how to solve this conflict?

            I think something is eating your backslash. So I would add additional 2
            backslashes in fromt of them. At least this works here:
            :exe '! "'.mybrowser.'" file:///'.substitute(expand("%:p"),' ','\\\%20',"g")


            regards,
            Christian


            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Tony Mechelynck
            ... Hm. Try a double percent sign. If it still doesn t work, write your command to a shell script and execute that: (untested) if has( win32 ) || has( win64 )
            Message 5 of 8 , Apr 3, 2008
            • 0 Attachment
              Franz Kelnreiter wrote:
              > Thank you for your hint but this does expand the filename alike.
              >
              > I tryed every kind of "%" "\%" '%' '\%', ex substitutes all these with
              > the filename. So how to write '%20' ??
              >
              > Franz

              Hm. Try a double percent sign. If it still doesn't work, write your
              command to a shell script and execute that: (untested)

              if has('win32') || has('win64') || has('win16')
              \ || has('dos32') || has('dos16')
              new $$$TEMP$$$.BAT
              else
              exe 'new' tempname()
              0put ='#!' . fnamemodify(&shell,':p')
              w
              !chmod 755 %
              endif
              let s = '"' . mybrowser . '" file:///'
              let s .= substitute(expand('%:p'),' ','%20','g')
              $put =s
              w
              exe '!' expand('%')
              x



              Best regards,
              Tony.
              --
              The more things change, the more they stay insane.

              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • frakel
              ... Great, Thank you for this solution.... greetings, Franz --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_use
              Message 6 of 8 , Apr 3, 2008
              • 0 Attachment
                On Apr 3, 11:46 am, "Christian Brabandt" <cbli...@...> wrote:
                > Am Do, 3.04.2008, 10:38, schrieb frakel:
                >
                > > I am struggling with the correct syntax for starting the browser with
                > > the file in the current buffer through the DOS commandline:
                > > I have played a lot around but get no working solution, my best one
                > > looks like this (in my _vimrc mapped to <F8>):
                >
                > > :exe '! "'.mybrowser.'" file:///'.substitute(expand("%:p"),' ',"\
                > > %20","g")
                >
                > > The problem is the substitution of the blanks in path of the file
                > > which have to be replaced with '%20' for html-files, but vim always
                > > expands '%' '\%' and whatever to the filename...
                >
                > > Has anyone an idea how to solve this conflict?
                >
                > I think something is eating your backslash. So I would add additional 2
                > backslashes in fromt of them. At least this works here:
                > :exe '! "'.mybrowser.'" file:///'.substitute(expand("%:p"),' ','\\\%20',"g")
                >
                > regards,
                > Christian
                Great, Thank you for this solution....
                greetings,
                Franz
                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • Ben Schmidt
                ... As well as the single quotes, you need one more backslash than this...because substitute will eat one (:help sub-replace-special) before :exe/Ex command
                Message 7 of 8 , Apr 4, 2008
                • 0 Attachment
                  Tony Mechelynck wrote:
                  > frakel wrote:
                  >> Hi all,
                  >>
                  >> I am struggling with the correct syntax for starting the browser with
                  >> the file in the current buffer through the DOS commandline:
                  >> I have played a lot around but get no working solution, my best one
                  >> looks like this (in my _vimrc mapped to<F8>):
                  >>
                  >> :exe '! "'.mybrowser.'" file:///'.substitute(expand("%:p"),' ',"\
                  >> %20","g")
                  >>
                  >> The problem is the substitution of the blanks in path of the file
                  >> which have to be replaced with '%20' for html-files, but vim always
                  >> expands '%' '\%' and whatever to the filename...
                  >>
                  >> Has anyone an idea how to solve this conflict?
                  >>
                  >> Thanks a lot,
                  >> franz
                  >
                  > In a double-quoted string, backslashes are used as escapes. Try using
                  > single quotes instead:
                  >
                  > :exe '! "' . mybrowser . '" file:///' . substitute(expand('%:p'),'
                  > ','\%20','g')
                  >
                  > Thus the :! command should see the backslash before the percent sign,
                  > unlike in your command above. I hope it will pass \% as % to the
                  > browser, but I haven't tested it.

                  As well as the single quotes, you need one more backslash than this...because
                  'substitute' will eat one (:help sub-replace-special) before :exe/Ex command
                  parsing does (:help cmdline-special).

                  Ben.




                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • Ben Schmidt
                  ... And the help references regarding the string quoting/escaping are ... Ben. --~--~---------~--~----~------------~-------~--~----~ You received this message
                  Message 8 of 8 , Apr 4, 2008
                  • 0 Attachment
                    Ben Schmidt wrote:
                    > Tony Mechelynck wrote:
                    >> frakel wrote:
                    >>> Hi all,
                    >>>
                    >>> I am struggling with the correct syntax for starting the browser with
                    >>> the file in the current buffer through the DOS commandline:
                    >>> I have played a lot around but get no working solution, my best one
                    >>> looks like this (in my _vimrc mapped to<F8>):
                    >>>
                    >>> :exe '! "'.mybrowser.'" file:///'.substitute(expand("%:p"),' ',"\
                    >>> %20","g")
                    >>>
                    >>> The problem is the substitution of the blanks in path of the file
                    >>> which have to be replaced with '%20' for html-files, but vim always
                    >>> expands '%' '\%' and whatever to the filename...
                    >>>
                    >>> Has anyone an idea how to solve this conflict?
                    >>>
                    >>> Thanks a lot,
                    >>> franz
                    >> In a double-quoted string, backslashes are used as escapes. Try using
                    >> single quotes instead:
                    >>
                    >> :exe '! "' . mybrowser . '" file:///' . substitute(expand('%:p'),'
                    >> ','\%20','g')
                    >>
                    >> Thus the :! command should see the backslash before the percent sign,
                    >> unlike in your command above. I hope it will pass \% as % to the
                    >> browser, but I haven't tested it.
                    >
                    > As well as the single quotes, you need one more backslash than this...because
                    > 'substitute' will eat one (:help sub-replace-special) before :exe/Ex command
                    > parsing does (:help cmdline-special).

                    And the help references regarding the string quoting/escaping are

                    :help expr-string
                    :help literal-string

                    Ben.




                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_use" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  Your message has been successfully submitted and would be delivered to recipients shortly.