> I am trying to write a simple function, which searches through > the whole buffer to fund a certain pattern and stops searching > when found the first match. I also want the function to > return a matched/not matched return code and given the caller > the line/column of the match if found.
You might try with the built-in search() function. There are some nuances to finding a match on the first line, but these can be overcome by going to *end* of the file, and then searching with wrapscan. Something like this untested function might do the trick: function! first(pat) let old_line = line('.') $ let result=search(a:pat, 'w') exec old_line return result endfunc You can read up on the nuances and flags of search() at :help search() -tim