Monday, November 21, 2011

Re: In script always search from start of buffer

On Sun, Nov 20, 2011 at 1:25 PM, Gary Johnson-4 [via VIM]
<[hidden email]> wrote:

> On 2011-11-20, porphyry5 wrote:
>> In a script, how can I get repeated searches always to begin at the start
>> of
>> the buffer?
>> If I precede the search with gg  or :cursor(1, 1) I get E492, with 1G I
>> get
>> E464.
>>
>> :map p$ ggdd:while @" != ""<CR>:b#<CR>:cursor (1, 1)<CR>:silent!
>> /^R"<CR>0i$<Space><Esc>:b#<CR>dd:endwhile
>
> I haven't looked closely at your mapping, but to use a normal-mode
> command such as gg in a script, that is, as an ex command, you must
> precede it with ":normal", as
>
>     :normal gg
>
> Similarly, to use a function as an ex command, you must precede it
> with ":call", as
>
>     :call cursor(1, 1)
>
> See
>
>     :help :normal
>     :help :call
>
> Another way to move the cursor to the first line of the buffer is to
> simply put the number 1 on a line by itself, or in a mapping like
> yours, as ":1<CR>".
>
> HTH,
> Gary
>

It certainly does help, thank you, particularly with reference to
:help :normal, because it seems that sometimes a normal-mode command
works as-is, other times it doesn't.  I originally wrote the script as

: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.


View this message in context: Re: In script always search from start of buffer
Sent from the Vim - General mailing list archive at Nabble.com.

--
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: