diff --git a/src/search.c b/src/search.c
index 1db967d..e2a83c6 100644
--- a/src/search.c
+++ b/src/search.c
@@ -4740,17 +4740,28 @@ find_pattern_in_path(ptr, dir, len, whole, skip_comments,
 			 * Isolate the file name.
 			 * Include the surrounding "" or <> if present.
 			 */
-			for (p = incl_regmatch.endp[0]; !vim_isfilec(*p); p++)
-			    ;
-			for (i = 0; vim_isfilec(p[i]); i++)
-			    ;
+			if (inc_opt != NULL && strstr((char *)inc_opt, "\\zs") != NULL)
+			{
+			    p = incl_regmatch.startp[0];
+			    i = incl_regmatch.endp[0] - incl_regmatch.startp[0];
+			}
+			else
+			{
+			    for (p = incl_regmatch.endp[0]; *p && !vim_isfilec(*p); p++)
+				;
+			    for (i = 0; vim_isfilec(p[i]); i++)
+				;
+			}
+
 			if (i == 0)
 			{
 			    /* Nothing found, use the rest of the line. */
 			    p = incl_regmatch.endp[0];
 			    i = (int)STRLEN(p);
 			}
-			else
+			else if (p > line) /* If there's \zs in the regexp, we
+					    * might check before the start of
+					    * the line. */
 			{
 			    if (p[-1] == '"' || p[-1] == '<')
 			    {
diff --git a/src/testdir/test17.in b/src/testdir/test17.in
index e59144f..08ad3eb 100644
--- a/src/testdir/test17.in
+++ b/src/testdir/test17.in
@@ -1,4 +1,6 @@
-Tests for "gf" on ${VAR}
+Tests for:
+- "gf" on ${VAR},
+- ":checkpath!" with various 'include' settings.
 
 STARTTEST
 :so small.vim
@@ -20,8 +22,99 @@ STARTTEST
 :endif
 gf
 :w! test.out
-:qa!
+:brewind
 ENDTEST
 
 	${CDIR}/test17a.in
 	$TDIR/test17a.in
+
+STARTTEST
+:" check for 'include' without \zs or \ze
+:lang C
+:!rm -f ./base.a
+:!rm -rf ./dir1
+:!mkdir -p dir1/dir2
+:e dir1/dir2/foo.a
+i#include   "bar.a"
+:w
+:e dir1/dir2/bar.a
+i#include      "baz.a"
+:w
+:e dir1/dir2/baz.a
+i#include            "foo.a"
+:w
+:e base.a
+:set path=dir1/dir2
+i#include    <foo.a>
+:w
+:redir! >>test.out
+:checkpath!
+:redir END
+:brewind
+ENDTEST
+
+STARTTEST
+:" check for 'include' with \zs and \ze
+:!rm -f ./base.b
+:!rm -rf ./dir1
+:!mkdir -p dir1/dir2
+:let &include='^\s*%inc\s*/\zs[^/]\+\ze'
+:function! DotsToSlashes()
+:  return substitute(v:fname, '\.', '/', 'g') . '.b'
+:endfunction
+:let &includeexpr='DotsToSlashes()'
+:e dir1/dir2/foo.b
+i%inc   /bar/
+:w
+:e dir1/dir2/bar.b
+i%inc      /baz/
+:w
+:e dir1/dir2/baz.b
+i%inc            /foo/
+:w
+:e base.b
+:set path=dir1/dir2
+i%inc    /foo/
+:w
+:redir! >>test.out
+:checkpath!
+:redir END
+:brewind
+ENDTEST
+
+STARTTEST
+:" check for 'include' with \zs and no \ze
+:!rm -f ./base.c
+:!rm -rf ./dir1
+:!mkdir -p dir1/dir2
+:let &include='^\s*%inc\s*\%([[:upper:]][^[:space:]]*\s\+\)\?\zs\S\+\ze'
+:function! StripNewlineChar()
+:  if v:fname =~ '\n$'
+:    return v:fname[:-2]
+:  endif
+:  return v:fname
+:endfunction
+:let &includeexpr='StripNewlineChar()'
+:e dir1/dir2/foo.c
+i%inc   bar.c
+:w
+:e dir1/dir2/bar.c
+i%inc      baz.c
+:w
+:e dir1/dir2/baz.c
+i%inc            foo.c
+:w
+:e dir1/dir2/FALSE.c
+i%inc            foo.c
+:w
+:e base.c
+:set path=dir1/dir2
+i%inc    FALSE.c foo.c
+:w
+:redir! >>test.out
+:checkpath!
+:redir END
+:brewind
+:q
+ENDTEST
+
diff --git a/src/testdir/test17.ok b/src/testdir/test17.ok
index 7e89364..0e75ea3 100644
--- a/src/testdir/test17.ok
+++ b/src/testdir/test17.ok
@@ -1,3 +1,33 @@
 This file is just to test "gf" in test 17.
 The contents is not important.
 Just testing!
+
+
+--- Included files in path ---
+dir1/dir2/foo.a
+dir1/dir2/foo.a -->
+  dir1/dir2/bar.a
+  dir1/dir2/bar.a -->
+    dir1/dir2/baz.a
+    dir1/dir2/baz.a -->
+      "foo.a"  (Already listed)
+
+
+--- Included files in path ---
+dir1/dir2/foo.b
+dir1/dir2/foo.b -->
+  dir1/dir2/bar.b
+  dir1/dir2/bar.b -->
+    dir1/dir2/baz.b
+    dir1/dir2/baz.b -->
+      foo  (Already listed)
+
+
+--- Included files in path ---
+dir1/dir2/foo.c
+dir1/dir2/foo.c -->
+  dir1/dir2/bar.c
+  dir1/dir2/bar.c -->
+    dir1/dir2/baz.c
+    dir1/dir2/baz.c -->
+      foo.c^@  (Already listed)
