Executing the following
?[\|(\|{
Gives me the expected results. I.E.
The cursor is placed at the closest previous '[' or '(' or '{'
Executing the following
/]\|)\|}
Gives me the expected results. I.E.
The cursor is placed on the closest next ']' or ')' or '}'
Yet these two functions:
function! PreviousDelimiter()
execute '?[\|(\|{'
execute ':nohls'
endfunction
" and
function! PreviousDelimiter()
execute '?[\|(\|{'
execute ':nohls'
endfunction
yield unexpected results. In each case, when the function
is called, the cursor is placed at the beginning of the line
of the first successful match, rather than on the target char.
Your help is appreciated and even moreso, pointers to
discussions on the relevant subjects.
Thanks
Tim
Here, you're using the thing mentioned at :help / or :help ? - they
are characterwise searches.
> Yet these two functions:
> function! PreviousDelimiter()
> execute '?[\|(\|{'
> execute ':nohls'
> endfunction
> " and
> function! PreviousDelimiter()
> execute '?[\|(\|{'
> execute ':nohls'
> endfunction
>
> yield unexpected results. In each case, when the function
> is called, the cursor is placed at the beginning of the line
> of the first successful match, rather than on the target char.
>
> Your help is appreciated and even moreso, pointers to
> discussions on the relevant subjects.
And here, you're using the thing mentioned at :help :/ and :help :?
- they are linewise searches that specify a line address. To get the
behavior that you want, either use the search() function, or use
"norm!" to make vim behave as though you typed the ? normal mode
command instead of the ? ex-mode command.
exe 'norm! ?[\|(\|{' . "\<CR>"
or
exe "norm! ?[\\|(\\|{\<CR>"
~Matt
":execute" runs its argument as an ex-command (the colon is unnecessary,
but, as you can see by starting a command-line with two or more colons,
it does no harm). In this case your search is run as a naked range,
which puts the cursor at the start of the line so found. See ":help
:range". Similarly, ":225" or ":exe 225" would put the cursor at the
start of the 225th line.
You might try
normal ?[\|(\|{
nohls
instead.
Best regards,
Tony.
--
What good is having someone who can walk on water if you don't follow
in his footsteps?
This won't work. And I gave a correct answer 6 hours ago.
~Matt
Well, I forgot to escape; and I happen to read this newsgroup
top-to-bottom when I get to it. Sometimes the answer is so evident that
I forget someone else might already have given it.
Regards,
Tony.
--
"I have to convince you, or at least snow you ..."
-- Prof. Romas Aleliunas, CS 435
cheers
tim