Thursday, January 1, 2015

In Vim, / (search in normal mode) and search function return different results

Just asked this question on stackoverflow but the comment shows it seems to be a version-specific problem.

I have a simple text file:

blah.
[{}]
[{foo}]

My cursor is at the beginning of the file. I want to search for (possibly empty) strings embraced with [{}].

So the regex pattern is "\[{.*}\]",right?

When I use the normal search

/\[{.*}\]

The cursor is relocated at the second line, good!

But if I use the search function

:echo search("\[{.*}\]")

The cursor goes to the final . of the first line and the result of echo is 1, meaning the first match is in line 1.

Can you reproduce this? And if yes, why and how can I get the same result as the normal search using a function?

I am running Arch Linux and my Vim version is 7.4.537 (the latest on Arch).

Thanks.

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: