user1146332
user1146332

Reputation: 2770

searchpair() always returns 0

it seems to be a dumb question, but it has to be posed.

I have just experimented with vim's functions and came across 'searchpair'. So i started to make use of it.

The buffer on which i employed the function looks like this:

xyz
xyz
[
xyz
xyz
[
xyz
]
xyz
xyz
]
xyz
xyz

And i positioned the cursor at the first line. After that i changed to Ex-mode an executed the command

echo searchpair('[', '', ']')

that puts 0 on the screen.

Obviously searchpair didn't find the pair of brackets in my buffer, so i played further with the arguments and the buffer. Nevertheless it returns always 0.

Studying :h searchpair() helps me neither.

Maybe someone of you experts can help me to gain some wisdom.

PS: i use

VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jul 12 2010 02:31:36)

Upvotes: 1

Views: 645

Answers (1)

romainl
romainl

Reputation: 196789

You forgot to escape your [].

This version:

:echo searchpair('\[','','\]')

works but only if it is executed when the cursor is on the character you want to match.

The number returned is the number of the line on which the match is found.

Also, : doesn't put you into "Ex mode", it puts you into "Command-line" mode.

Upvotes: 2

Related Questions