:global problem

23 views
Skip to first unread message

Efraim Yawitz

unread,
Jul 5, 2009, 3:26:52 AM7/5/09
to vim...@googlegroups.com
I just searched the archives for every message about E488 before sending this because it seemed so simple, but I didn't find the answer.

I tried to use :g/abc/insert\ etc. just like in the help, and I always get "E488 - Trailing characters".  Do I have some setting wrong?

Thanks,

Ephraim

Tim Chase

unread,
Jul 5, 2009, 7:38:57 AM7/5/09
to vim...@googlegroups.com
> I tried to use :g/abc/insert\ etc. just like in the help, and I always get
> "E488 - Trailing characters". Do I have some setting wrong?

The problem seems to reside with the ":insert" continuation as
other commands work just fine. I found the example that looks
like yours at

:help :insert

(would have helped if you had included _where_ in the help your
"just like in the help" came from, as the help is huge :)


When these commands are used with :global or :vglobal
then the lines are obtained from the text following the
command. Separate lines with a NL escaped with a
backslash:
:global/abc/insert\
one line\
another line
The final "." is not needed then.

Typing that example verbatim does fail in the way you describe.
This looks like an error in the help or an error in :insert (at
least from Vim6.2 onward, which is the oldest version I have on
hand for testing). Just to be sure, I also tried copying the
example into a script and sourcing it. Same error.

As a work around, you can yank the text you wish to insert and
then use

" scratch register
:g/abc/put
" put the contents of register "b"
:g/abc/put b

to put the text afterwards. Or, if you want to use a variable to
hold the instead of tromping a register:

:g/abc/put=my_variable_name

Peculiarly, the "put =" notation treats double-quotes as comment
delimiters which means to put in a raw string with newlines, you
have to use

:g/abc/put=\"one\ntwo\nthree\"

escaping the double-quotes. (Using single quotes prevents
treatment of the "\n" as a newline; tried with various
alternatives such as ^J, ^M, ^V^J, ^V^M, and \r but none of them
worked within single-quoted strings)

Hope this helps (1) confirm that you're not crazy and (2) gets
you a workaround to accomplish a similar behavior.

-tim


Efraim Yawitz

unread,
Jul 5, 2009, 7:45:40 AM7/5/09
to vim...@googlegroups.com
On Sun, Jul 5, 2009 at 2:38 PM, Tim Chase <v...@tim.thechases.com> wrote:

> I tried to use :g/abc/insert\ etc. just like in the help, and I always get
> "E488 - Trailing characters".  Do I have some setting wrong?

The problem seems to reside with the ":insert" continuation as
other commands work just fine.  I found the example that looks
like yours at

The problem seems to be with :insert itself, since I get the same error when I just type :insert\

  :help :insert

(would have helped if you had included _where_ in the help your
"just like in the help" came from, as the help is huge :)

Sorry; I guess I thought this would be so obvious that someone would immediately see what I was doing wrong.

Efraim Yawitz

unread,
Jul 5, 2009, 10:14:43 AM7/5/09
to vim...@googlegroups.com
On Sun, Jul 5, 2009 at 2:38 PM, Tim Chase <v...@tim.thechases.com> wrote:

> I tried to use :g/abc/insert\ etc. just like in the help, and I always get
> "E488 - Trailing characters".  Do I have some setting wrong?

The problem seems to reside with the ":insert" continuation as
other commands work just fine.  I found the example that looks
like yours at

  :help :insert

A little debugging revealed that this behavior is according to design (but not as described in the help).

In ex_cmds.h the :insert command is configured as:

EX(CMD_insert,        "insert",    ex_append,
            BANG|RANGE|TRLBAR|CMDWIN|MODIFY),

without the EXTRA bit set which is defined as:

#define EXTRA        0x004    /* allow extra args after command name */

:insert (and :append) do not allow any arguments.  The only question is, was this always this way, and what is the correct behavior?

Ephraim

Efraim Yawitz

unread,
Jul 5, 2009, 10:34:26 AM7/5/09
to vim...@googlegroups.com


On Sun, Jul 5, 2009 at 5:14 PM, Efraim Yawitz <efraim...@gmail.com> wrote:

A little debugging revealed that this behavior is according to design (but not as described in the help).

In ex_cmds.h the :insert command is configured as:

EX(CMD_insert,        "insert",    ex_append,
            BANG|RANGE|TRLBAR|CMDWIN|MODIFY),

without the EXTRA bit set which is defined as:

#define EXTRA        0x004    /* allow extra args after command name */

:insert (and :append) do not allow any arguments.  The only question is, was this always this way, and what is the correct behavior?


Now I looked at the source of vim 4.6 and I found this in the table of ex command definitions:

    {(char_u *)"insert",        BANG+RANGE+TRLBAR},            /* not supported */

so it seems that at one point :insert was not supported at all

Efraim Yawitz

unread,
Jul 6, 2009, 10:16:35 AM7/6/09
to vim...@googlegroups.com
Anybody have anything more on this? Bram? Is it really a bug?

Andy Wokula

unread,
Jul 6, 2009, 10:46:39 AM7/6/09
to vim...@googlegroups.com
Efraim Yawitz schrieb:

> Anybody have anything more on this? Bram? Is it really a bug?

Hmm, using a trailing backslash for line continuation is a
very special thing added in Vim7:

:h version7
- When ":append", ":insert" or ":change" is used with ":global", get the
inserted lines from the command. Can use backslash-NL to separate lines.

This works for me:

:g/abc/insert\^@Line1\^@Line2

where ^@ is one character inserted with CTRL-V_CTRL-J or CTRL-K_N_U etc.

--
Andy

Efraim Yawitz

unread,
Jul 6, 2009, 12:18:36 PM7/6/09
to vim...@googlegroups.com


On Mon, Jul 6, 2009 at 5:46 PM, Andy Wokula <anw...@yahoo.de> wrote:

This works for me:

:g/abc/insert\^@Line1\^@Line2

where ^@ is one character inserted with CTRL-V_CTRL-J or CTRL-K_N_U etc.

Right, that works fine, but is that what the help means?

Tim Chase

unread,
Jul 6, 2009, 12:49:36 PM7/6/09
to vim...@googlegroups.com
>> This works for me:
>>
>> :g/abc/insert\^@Line1\^@Line2
>>
>> where ^@ is one character inserted with CTRL-V_CTRL-J or CTRL-K_N_U etc.
>
> Right, that works fine, but is that what the help means?

The help _does_ seem to suggest that one can type

1) colon
2) g
3) slash
4) regexp
5) slash
6) i[nsert]
7) backslash
8) enter (instead of CTRL-V_CTRL-J or CTRL-K_N_U)
9) (continue adding your text to insert)

However step #8 errors out in the way mentioned by the OP before
it allows you to "finish" the insertion command.

The unintuitive solution would be to change the help to detail
Andy's findings. However, I think a better solution would
involve making the terminal-backslash treat the newline as the
null character and continue accepting input as the :insert
command normally does. This would align with how I read the help
and be more intuitive.


Separate lines with a NL escaped with a backslash

Confusion is compounded in the help by the use of the text "NL"
which can ambiguously be expanded as either "New-line" (ASCII
0x0a) or "Null" (ASCII 0x00). Both ":help NL" and ":help c_<nl>"
take you to places where <enter> is being hit, not the null ^@
internal EOL character is documented (":help NL-used-for-Nul").

Just MHO.

-tim

Andy Wokula

unread,
Jul 6, 2009, 1:07:35 PM7/6/09
to vim...@googlegroups.com
Efraim Yawitz schrieb:

I'm not sure, but it looks like a bug -- the NL is confusing and
readability is gone. see also Tim's post ...

And to make it work within a script, a different notation is required:
:exec "g/abc/insert\\\nLine1\\\nLine2"

Anyway:
:insert is an old Vi thing -- as help states, it can also confuse :if
statements etc, so I'd only use it in very "simple" situations.

--
Andy

Bram Moolenaar

unread,
Jul 6, 2009, 4:06:40 PM7/6/09
to Andy Wokula, vim...@googlegroups.com

Andy Wokula wrote:

I think the example in the help worked at some point, thus it does look
like it's broken. I'll find out why.

Note that this is only supposed to work when used in a script, not when
typed. It's quite useless to type an :insert command.

--
hundred-and-one symptoms of being an internet addict:
57. You begin to wonder how on earth your service provider is allowed to call
200 hours per month "unlimited."

/// Bram Moolenaar -- Br...@Moolenaar.net -- 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 ///

Efraim Yawitz

unread,
Jul 7, 2009, 3:53:48 AM7/7/09
to vim...@googlegroups.com


On Mon, Jul 6, 2009 at 8:07 PM, Andy Wokula <anw...@yahoo.de> wrote:
Anyway:
:insert is an old Vi thing -- as help states, it can also confuse :if
statements etc, so I'd only use it in very "simple" situations.


Agreed, but it seemed like it could be useful in those simple situations, i.e., adding a blank line before or after every occurrence of 'foo'.  (Of course, I could do it just as well with :pu)

Tony Mechelynck

unread,
Jul 8, 2009, 11:24:12 AM7/8/09
to vim...@googlegroups.com
On 05/07/09 13:45, Efraim Yawitz wrote:
[...]

> Sorry; I guess I thought this would be so obvious that someone would
> immediately see what I was doing wrong.

It always helps to be as explicit as you can be. (Even seasoned Vimmers
sometimes misread what is there in the post, so what you omitted from
your post has that more chance of being misunderstood, or of not being
understood at all.)


Best regards,
Tony.


--
hundred-and-one symptoms of being an internet addict:

65. The last time you looked at the clock it was 11:30pm, and in what seems
like only a few seconds later, your sister runs past you to catch her
7am school bus.

Reply all
Reply to author
Forward
0 new messages