> On Mon, Nov 21, 2011 at 4:44 AM, Tim Chase<vim@tim.thechases.com> wrote:
>
>> In normal-mode, the number prefixing a search is a count, to find the Nth
>> match. In command-line mode (entered when you hit the colon), it's the line
>> at which to start.
>>
>>> But one thing still puzzles me: in fact, I had tried each of gg, 1G
>>> and cursor with and without a leading<:>, with and without a trailing
>>> <space>, with and without a trailing<CR>; and, as I originally wrote
>>> the script, it read
>>>
>>> :map p$ ggdd:while @" != ""<CR>:b#<CR>gg:silent!
>>> /^R"<CR>0i$<Space><Esc>:b#<CR>dd:endwhile
>>>
>>> in which the first gg works, the second gg fails with E492, and I
>>> would very much like to know why.
>>
>> Strange things happen when you mix command-line mode and looping. When you
>> start the ":while", Vim starts a command-entering mode waiting for the
>> "endwhile". Thus the ":" before the "b#" is optional, and the "gg" is then
>> treated as an Ex command (triggering the E492).
>>
>> -tim
>>
> Thank you very much, that makes it very clear, and also resolves
> another thing that had been bugging me. Somewhere I had got the
> notion that<:> was optional in scripts, kept encountering situations
> where it was not true, and took to colon-izing everything as it would
> be in the buffer command line. But actually the<:> is optional only
> if the script is implicitly in command mode due to a previous command,
> like a loop structure. So presumably one would also be in the same
> situation using a | separated string of commands in the command line;
> they could be of the form
> :command1 | command2 | command3...<CR>
> and the initial<:> would extend to subsequent commands on the same
> line. And presumably any normal mode commands in such string would
> fail unless prepended by<normal>
>
Scripts _are_ implicitly in command-line mode everywhere: e.g. view the
example vimrc by using
:view $VIMRUNTIME/vimrc_example.vim
and you will notice that none of its lines starts with a colon. However,
the {rhs} of a mapping is not a full script line, and _it_ is not
implicitly in command-line mode.
The reason why normal-mode commands must be prefixed by "normal" in
scripts is that the :normal command executes its argument as a
normal-mode command (or set of commands). If you want to execute :normal
as part of a string of bar-separated concatenated ex-commands (and other
than at the end) you must wrap it in an :execute because :normal would
see the bar as part of its arguments:
:cmd1 | cmd2 | exe "normal w3li \e" | cmd3 | etc...
Best regards,
Tony.
--
Travel important today; Internal Revenue men arrive tomorrow.
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment