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

Bug: ":confirm w" only works once

Expand Messages
  • Michael Schaap
    Hi, When editing a read-only file, :confirm w only works the first time you use it in a session. The second time you try to use it, you simply get an error
    Message 1 of 7 , Feb 27, 2007
    • 0 Attachment
      Hi,

      When editing a read-only file, ":confirm w" only works the first time
      you use it in a session. The second time you try to use it, you simply
      get an error message, as if you didn't use ":confirm".
      The same problem occurs when using ":set confirm".

      To recreate:

      $ echo Hello > hello.txt
      $ chmod 400 hello.txt
      $ vim -u NONE hello.txt
      :set nocompatible " or you won't be able to overwrite at all
      A, World<Esc>
      :confirm w
      'readonly' option is set for "qq".
      Do you wish to write anyway?
      (Y)es, [N]o: y
      A!<Esc>
      :confirm w
      E505: "qq" is read-only (add ! to override)

      This is using 7.0.203, but it has been happening for quite a while. An
      old 6.3 does the same thing.

      – Michael
    • Yakov Lerner
      ... You see this behaviour because the first :confirm w(or :w! , for this matter) resets the ro option. This is the reason the 2nd :confirm w doesn t ask
      Message 2 of 7 , Feb 28, 2007
      • 0 Attachment
        On 2/27/07, Michael Schaap <vim@...> wrote:
        > Hi,
        >
        > When editing a read-only file, ":confirm w" only works the first time
        > you use it in a session. The second time you try to use it, you simply
        > get an error message, as if you didn't use ":confirm".
        > The same problem occurs when using ":set confirm".
        >
        > To recreate:
        >
        > $ echo Hello > hello.txt
        > $ chmod 400 hello.txt
        > $ vim -u NONE hello.txt
        > :set nocompatible " or you won't be able to overwrite at all
        > A, World<Esc>
        > :confirm w
        > 'readonly' option is set for "qq".
        > Do you wish to write anyway?
        > (Y)es, [N]o: y
        > A!<Esc>
        > :confirm w
        > E505: "qq" is read-only (add ! to override)
        >
        > This is using 7.0.203, but it has been happening for quite a while. An
        > old 6.3 does the same thing.

        You see this behaviour because the first :confirm w(or ':w!',
        for this matter) resets the 'ro' option. This is the reason the 2nd
        ':confirm w' doesn't ask anything. You can see yourself if you do
        'set ro?' before and after first ':confirm w'.
        :set ro?
        readonly
        :confirm w
        ... (Y)es, [N]o: y
        :set ro?
        noreadonly

        As you see, the 'ro' option has been reset. This is
        the reason the following ':confirm w' does not ask for
        the confirmation.

        AFAIK, vim always behaved this way -- that is,
        the ':w!' would reset the ro flag.

        But notice that inserting text into 'ro' file does not reset the 'ro'
        flag by itself.
        It warns (modifying the readonly file). but the 'ro' flag remains. After
        :w!, 'ro' flag is reset.

        Yakov
      • A.J.Mechelynck
        ... Why then does the second :confirm w give E505: qq is read-only (add ! to override) ? Best regards, Tony. -- Your fault: core dumped
        Message 3 of 7 , Feb 28, 2007
        • 0 Attachment
          Yakov Lerner wrote:
          > On 2/27/07, Michael Schaap <vim@...> wrote:
          >> Hi,
          >>
          >> When editing a read-only file, ":confirm w" only works the first time
          >> you use it in a session. The second time you try to use it, you simply
          >> get an error message, as if you didn't use ":confirm".
          >> The same problem occurs when using ":set confirm".
          >>
          >> To recreate:
          >>
          >> $ echo Hello > hello.txt
          >> $ chmod 400 hello.txt
          >> $ vim -u NONE hello.txt
          >> :set nocompatible " or you won't be able to overwrite at all
          >> A, World<Esc>
          >> :confirm w
          >> 'readonly' option is set for "qq".
          >> Do you wish to write anyway?
          >> (Y)es, [N]o: y
          >> A!<Esc>
          >> :confirm w
          >> E505: "qq" is read-only (add ! to override)
          >>
          >> This is using 7.0.203, but it has been happening for quite a while. An
          >> old 6.3 does the same thing.
          >
          > You see this behaviour because the first :confirm w(or ':w!',
          > for this matter) resets the 'ro' option. This is the reason the 2nd
          > ':confirm w' doesn't ask anything. You can see yourself if you do
          > 'set ro?' before and after first ':confirm w'.
          > :set ro?
          > readonly
          > :confirm w
          > ... (Y)es, [N]o: y
          > :set ro?
          > noreadonly
          >
          > As you see, the 'ro' option has been reset. This is
          > the reason the following ':confirm w' does not ask for
          > the confirmation.
          >
          > AFAIK, vim always behaved this way -- that is,
          > the ':w!' would reset the ro flag.
          >
          > But notice that inserting text into 'ro' file does not reset the 'ro'
          > flag by itself.
          > It warns (modifying the readonly file). but the 'ro' flag remains. After
          > :w!, 'ro' flag is reset.
          >
          > Yakov
          >

          Why then does the second ":confirm w" give 'E505: "qq" is read-only (add ! to
          override)' ?


          Best regards,
          Tony.
          --
          Your fault: core dumped
        • Yakov Lerner
          ... Because file-on-disk has read-only permissions. But the set readonly? option is off. Yakov
          Message 4 of 7 , Feb 28, 2007
          • 0 Attachment
            On 2/28/07, A.J.Mechelynck <antoine.mechelynck@...> wrote:
            > Yakov Lerner wrote:
            > > On 2/27/07, Michael Schaap <vim@...> wrote:
            > >> Hi,
            > >>
            > >> When editing a read-only file, ":confirm w" only works the first time
            > >> you use it in a session. The second time you try to use it, you simply
            > >> get an error message, as if you didn't use ":confirm".
            > >> The same problem occurs when using ":set confirm".
            > >>
            > >> To recreate:
            > >>
            > >> $ echo Hello > hello.txt
            > >> $ chmod 400 hello.txt
            > >> $ vim -u NONE hello.txt
            > >> :set nocompatible " or you won't be able to overwrite at all
            > >> A, World<Esc>
            > >> :confirm w
            > >> 'readonly' option is set for "qq".
            > >> Do you wish to write anyway?
            > >> (Y)es, [N]o: y
            > >> A!<Esc>
            > >> :confirm w
            > >> E505: "qq" is read-only (add ! to override)
            > >>
            > >> This is using 7.0.203, but it has been happening for quite a while. An
            > >> old 6.3 does the same thing.
            > >
            > > You see this behaviour because the first :confirm w(or ':w!',
            > > for this matter) resets the 'ro' option. This is the reason the 2nd
            > > ':confirm w' doesn't ask anything. You can see yourself if you do
            > > 'set ro?' before and after first ':confirm w'.
            > > :set ro?
            > > readonly
            > > :confirm w
            > > ... (Y)es, [N]o: y
            > > :set ro?
            > > noreadonly
            > >
            > > As you see, the 'ro' option has been reset. This is
            > > the reason the following ':confirm w' does not ask for
            > > the confirmation.
            > >
            > > AFAIK, vim always behaved this way -- that is,
            > > the ':w!' would reset the ro flag.
            > >
            > > But notice that inserting text into 'ro' file does not reset the 'ro'
            > > flag by itself.
            > > It warns (modifying the readonly file). but the 'ro' flag remains. After
            > > :w!, 'ro' flag is reset.
            > >
            > > Yakov
            > >
            >
            > Why then does the second ":confirm w" give 'E505: "qq" is read-only (add ! to
            > override)' ?

            Because file-on-disk has read-only permissions.
            But the 'set readonly?' option is off.

            Yakov
          • Bram Moolenaar
            ... What happens when readonly is set is that the :confirm asks you if you want to override it. If you select yes then it will behave as if you did
            Message 5 of 7 , Feb 28, 2007
            • 0 Attachment
              Michael Schaap wrote:

              > When editing a read-only file, ":confirm w" only works the first time
              > you use it in a session. The second time you try to use it, you simply
              > get an error message, as if you didn't use ":confirm".
              > The same problem occurs when using ":set confirm".
              >
              > To recreate:
              >
              > $ echo Hello > hello.txt
              > $ chmod 400 hello.txt
              > $ vim -u NONE hello.txt
              > :set nocompatible " or you won't be able to overwrite at all
              > A, World<Esc>
              > :confirm w
              > 'readonly' option is set for "qq".
              > Do you wish to write anyway?
              > (Y)es, [N]o: y
              > A!<Esc>
              > :confirm w
              > E505: "qq" is read-only (add ! to override)
              >
              > This is using 7.0.203, but it has been happening for quite a while. An
              > old 6.3 does the same thing.
              >
              > – Michael

              What happens when 'readonly' is set is that the ":confirm" asks you if
              you want to override it. If you select "yes" then it will behave as if
              you did ":w!". If you do the same with 'readonly' off you don't get the
              prompt, but writing fails for ":w", only ":w!" works.

              Note that when 'readonly' is set then ":w" results in E45, while a
              read-only file gives E505. They are two different things, but both are
              overruled with ":w!". We don't have a separate "!" for each situation.

              Perhaps the E505 should also trigger ":confirm w" to ask for writing
              anyway. That's more difficult, but would be what you expect.

              --
              hundred-and-one symptoms of being an internet addict:
              222. You send more than 20 personal e-mails a day.

              /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
              /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
              \\\ download, build and distribute -- http://www.A-A-P.org ///
              \\\ help me help AIDS victims -- http://ICCF-Holland.org ///
            • Michael Schaap
              ... And indeed, as Yakov remarked (and is documented in vim), :w! resets readonly . But although the readonly option is no longer set, the file is still
              Message 6 of 7 , Mar 1, 2007
              • 0 Attachment
                On 28-Feb-2007 22:38, Bram Moolenaar wrote:
                > Michael Schaap wrote:
                >
                >
                >> When editing a read-only file, ":confirm w" only works the first time
                >> you use it in a session. The second time you try to use it, you simply
                >> get an error message, as if you didn't use ":confirm".
                >> The same problem occurs when using ":set confirm".
                >>
                >> To recreate:
                >>
                >> $ echo Hello > hello.txt
                >> $ chmod 400 hello.txt
                >> $ vim -u NONE hello.txt
                >> :set nocompatible " or you won't be able to overwrite at all
                >> A, World<Esc>
                >> :confirm w
                >> 'readonly' option is set for "qq".
                >> Do you wish to write anyway?
                >> (Y)es, [N]o: y
                >> A!<Esc>
                >> :confirm w
                >> E505: "qq" is read-only (add ! to override)
                >>
                >> This is using 7.0.203, but it has been happening for quite a while. An
                >> old 6.3 does the same thing.
                >>
                >> – Michael
                >>
                >
                > What happens when 'readonly' is set is that the ":confirm" asks you if
                > you want to override it. If you select "yes" then it will behave as if
                > you did ":w!". If you do the same with 'readonly' off you don't get the
                > prompt, but writing fails for ":w", only ":w!" works.
                >
                And indeed, as Yakov remarked (and is documented in vim), ":w!" resets
                'readonly'.
                But although the 'readonly' option is no longer set, the file is still
                (correctly) read-only on the file system. Perhaps it should only reset
                'readonly' if this isn't the case (e.g. 'readonly' manually set, or when
                running "view")? After all, the option _is_ initially set when the file
                is read-only (although this doesn't appear to be documented).

                > Note that when 'readonly' is set then ":w" results in E45, while a
                > read-only file gives E505. They are two different things, but both are
                > overruled with ":w!". We don't have a separate "!" for each situation.
                >
                > Perhaps the E505 should also trigger ":confirm w" to ask for writing
                > anyway. That's more difficult, but would be what you expect.
                >
                You mean that ":confirm w" should trigger a dialog in case of E505,
                right? Yeah, that would make sense.
                In the meantime, reading the 'readonly' help entry, I found the
                'cpoptions' 'Z' flag, which solves my problem, so I added it to my .vimrc.

                Thanks,

                - Michael
              • edfyoungsmor@youngs.de
                Die von Ihnen genutzte eMail-Adresse (*@youngs.de) existiert nicht oder existiert nicht mehr.
                Message 7 of 7 , Mar 1, 2007
                • 0 Attachment
                  Die von Ihnen genutzte eMail-Adresse (*@...) existiert nicht oder existiert nicht mehr.
                Your message has been successfully submitted and would be delivered to recipients shortly.