In insert mode, searchpos('$') skips first match.

Steps to reproduce:
  $ vim -u NONE -N
  :call setline(1, ['abc', 'abc', 'abc'])
  :call cursor(2, 3)
  :inoremap <expr> S S()
  :function! S()
  :  echo searchpos('$', 'n')
  :  return ''
  :endfunction
  iS
  [3, 4]

  =====buffer=====
  1: a b c

  2: a b|c
        ^cursor
  3: a b c
          ^matched
  ================

I think this sould be matched at [2, 4].
I wrote patch for this problem.
Please check the attached patch.

-- 
Yukihiro Nakadaira - [email protected]

-- 
-- 
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/search.c b/src/search.c
index 1145558..de94ec9 100644
--- a/src/search.c
+++ b/src/search.c
@@ -761,7 +761,9 @@ searchit(win, buf, pos, dir, pat, count, options, pat_use, 
stop_lnum, tm)
                                        && (int)endpos.col - 1
                                             < (int)start_pos.col + extra_col)
                                    : ((int)matchpos.col
-                                                 - (ptr[matchpos.col] == NUL)
+                                                 - ((State & INSERT)
+                                                     ? 0
+                                                     : (ptr[matchpos.col] == 
NUL))
                                            < (int)start_pos.col + extra_col)))
                        {
                            /*
diff --git a/src/testdir/test_searchpos.vim b/src/testdir/test_searchpos.vim
index 4a1e024..23194d2 100644
--- a/src/testdir/test_searchpos.vim
+++ b/src/testdir/test_searchpos.vim
@@ -26,3 +26,59 @@ func Test_searchpos()
   q!
 
 endfunc
+
+func Test_searchpos_eol_in_insertmode()
+  new one
+
+  call setline(1, ['abc', 'abc', 'abc'])
+
+  inoremap <special> <expr> ISearchPos($,n) <SID>ISearchPos('$', 'n')
+  inoremap <special> <expr> ISearchPos($,nb) <SID>ISearchPos('$', 'nb')
+  inoremap <special> <expr> ISearchPos($,nc) <SID>ISearchPos('$', 'nc')
+  inoremap <special> <expr> ISearchPos($,nbc) <SID>ISearchPos('$', 'nbc')
+
+  call cursor(2, 3)
+  normal iISearchPos($,n)
+  call assert_equal([2, 4], s:pos)
+
+  call cursor(2, 3)
+  normal iISearchPos($,nb)
+  call assert_equal([1, 4], s:pos)
+
+  call cursor(2, 3)
+  normal iISearchPos($,nc)
+  call assert_equal([2, 4], s:pos)
+
+  call cursor(2, 3)
+  normal iISearchPos($,nbc)
+  call assert_equal([1, 4], s:pos)
+
+  call cursor(2, 3)
+  normal aISearchPos($,n)
+  call assert_equal([3, 4], s:pos)
+
+  call cursor(2, 3)
+  normal aISearchPos($,nb)
+  call assert_equal([1, 4], s:pos)
+
+  call cursor(2, 3)
+  normal aISearchPos($,nc)
+  call assert_equal([2, 4], s:pos)
+
+  call cursor(2, 3)
+  normal aISearchPos($,nbc)
+  call assert_equal([2, 4], s:pos)
+
+  iunmap ISearchPos($,n)
+  iunmap ISearchPos($,nb)
+  iunmap ISearchPos($,nc)
+  iunmap ISearchPos($,nbc)
+
+  q!
+endfunc
+
+function! s:ISearchPos(pat, flag)
+  let s:pos = searchpos(a:pat, a:flag)
+  return ''
+endfunction
+

Raspunde prin e-mail lui