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
> 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 :)
> 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?
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
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.
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
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
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 ///
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.
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.