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

Can't see what substitution will do

Expand Messages
  • Walter Briscoe
    This is a minor problem. It has irritated me occasionally when I hit it. This morning, I was bold enough to think I could deal with it. The c flag of the
    Message 1 of 2 , Dec 6, 2002
    • 0 Attachment
      This is a minor problem. It has irritated me occasionally when I hit it.
      This morning, I was bold enough to think I could deal with it.
      The c flag of the :substitute command puts out a confirmation message on
      each change. This shows the affected data and the transforming
      expression. It does NOT show the expected result. When the next
      substitution causes the first to disappear, the result is cryptic. The
      following demonstration was done on a 5 line 80 byte screen to reduce
      bandwidth in presenting the problem and the proposed solution. I then
      narrowed the presentation to avoid long lines in the email. It presents
      a simple change involving special replacement characters.

      The following is a sequence of snapshots from vim

      +--------------------------------------------------------------------+
      |abcdefghij |
      |2 |
      |3 |
      |4 |
      |"data" 6L, 41C 1,1 Top |
      +--------------------------------------------------------------------+

      I enter a substitution command

      +--------------------------------------------------------------------+
      |abcdefghij |
      |2 |
      |3 |
      |4 |
      |:%s/[aeiou]/ vowel(&) /c |
      +--------------------------------------------------------------------+

      Vim highlights the a - I don't know how to show that - and invites an
      input. I type y to do a change.

      +--------------------------------------------------------------------+
      |abcdefghij |
      |2 |
      |3 |
      |4 |
      |replace with vowel(&) (y/n/a/q/l/^E/^Y)? 1,1 Top |
      +--------------------------------------------------------------------+

      Next invitation. What did the first change actually do?

      +--------------------------------------------------------------------+
      |2 |
      |3 |
      |4 |
      |klmnopqrstuvwzyz |
      |replace with vowel(&) (y/n/a/q/l/^E/^Y)? 5,5 50% |
      +--------------------------------------------------------------------+

      I suggest the following for the view with the "highlighted" a:

      +--------------------------------------------------------------------+
      |abcdefghij |
      |2 |
      |3 |
      |4 |
      |replace with / vowel(a) / (y/n/a/q/l/^E/^Y)? 1,1 Top |
      +--------------------------------------------------------------------+

      The following change to the code does this:

      C:\wfb\vim\bld\vim61> diff -c src/0ex_cmds.c src/ex_cmds.c
      *** src/0ex_cmds.c Wed Nov 6 15:49:12 2002
      --- src/ex_cmds.c Fri Dec 6 12:45:10 2002
      ***************
      *** 3733,3742 ****
      i = msg_scroll;
      msg_scroll = 0; /* truncate msg when needed */
      msg_no_more = TRUE;
      ! /* write message same highlighting as for wait_return */
      ! smsg_attr(hl_attr(HLF_R),
      ! (char_u *)_("replace with %s (y/n/a/q/l/^E/^Y)?"),
      ! sub);
      msg_no_more = FALSE;
      msg_scroll = i;
      showruler(TRUE);
      --- 3733,3764 ----
      i = msg_scroll;
      msg_scroll = 0; /* truncate msg when needed */
      msg_no_more = TRUE;
      !
      ! {
      ! char_u *new_start_mimic;
      !
      ! /*
      ! * 3. Find the value of the substitution
      ! */
      ! /* get length of substitution part */
      ! sublen = vim_regsub_multi(®match, sub_firstlnum,
      ! sub, sub_firstline, FALSE, p_magic, TRUE);
      ! needed_len = sublen;
      ! new_start_len = needed_len + 50;
      ! if ((new_start_mimic = alloc_check(new_start_len)) == NULL)
      ! goto outofmem;
      ! *new_start_mimic = NUL;
      ! new_end = new_start_mimic;
      ! (void)vim_regsub_multi(®match, sub_firstlnum,
      ! sub, new_end, TRUE, p_magic, TRUE);
      !
      ! /* write message same highlighting as for wait_return */
      ! smsg_attr(hl_attr(HLF_R),
      ! (char_u *)_("replace with %c%s%c (y/n/a/q/l/^E/^Y)?"),
      ! delimiter, new_start_mimic, delimiter);
      ! vim_free(new_start_mimic);
      ! }
      !
      msg_no_more = FALSE;
      msg_scroll = i;
      showruler(TRUE);

      C:\wfb\vim\bld\vim61>

      I am posting this to both vim@... and vim-dev@.... Those
      vim@... readers unconcerned with the internals of vim should ignore
      the code changes. The code is at the proof of concept level. It is
      mainly a copy of code done later. Bram will doubtless want it changed if
      the concept is accepted.
      --
      Walter Briscoe
    • Bram Moolenaar
      [only copied to vim-dev, this is about a new feature] ... [...] ... In this specific case replacing the & with the actual text makes it clearer. However, if
      Message 2 of 2 , Dec 22, 2002
      • 0 Attachment
        [only copied to vim-dev, this is about a new feature]

        Walter Briscoe wrote:

        > This is a minor problem. It has irritated me occasionally when I hit it.
        > This morning, I was bold enough to think I could deal with it.
        > The c flag of the :substitute command puts out a confirmation message on
        > each change. This shows the affected data and the transforming
        > expression. It does NOT show the expected result. When the next
        > substitution causes the first to disappear, the result is cryptic. The
        > following demonstration was done on a 5 line 80 byte screen to reduce
        > bandwidth in presenting the problem and the proposed solution. I then
        > narrowed the presentation to avoid long lines in the email. It presents
        > a simple change involving special replacement characters.

        [...]

        > +--------------------------------------------------------------------+
        > |2 |
        > |3 |
        > |4 |
        > |klmnopqrstuvwzyz |
        > |replace with vowel(&) (y/n/a/q/l/^E/^Y)? 5,5 50% |
        > +--------------------------------------------------------------------+
        >
        > I suggest the following for the view with the "highlighted" a:
        >
        > +--------------------------------------------------------------------+
        > |abcdefghij |
        > |2 |
        > |3 |
        > |4 |
        > |replace with / vowel(a) / (y/n/a/q/l/^E/^Y)? 1,1 Top |
        > +--------------------------------------------------------------------+

        In this specific case replacing the "&" with the actual text makes it
        clearer. However, if the matched text is long (e.g. ".*") it will
        actually become more confusing.

        The idea of the question is that you have some idea of what kind of
        replacement is going to take place. The position of the match is the
        most important thing that may make you decide to skip the replacement.
        What the new text is would hardly ever matter, you probably already know
        it anyway. I don't find it worth adding code for this.

        --
        hundred-and-one symptoms of being an internet addict:
        105. When someone asks you for your address, you tell them your URL.

        /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
        /// Creator of Vim - Vi IMproved -- http://www.vim.org \\\
        \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
        \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html ///
      Your message has been successfully submitted and would be delivered to recipients shortly.