summaryrefslogtreecommitdiff
path: root/src/search.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-07-24 17:33:05 +0200
committerBram Moolenaar <Bram@vim.org>2016-07-24 17:33:05 +0200
commit6835dc61aebca2b602d85a9d63c449ace58683b4 (patch)
tree4b7803caa1400d5c9de8c9ce25929e0288603876 /src/search.c
parent73ac0c4281a3606651604a3cbcc334bfb3859a87 (diff)
downloadvim-git-6835dc61aebca2b602d85a9d63c449ace58683b4.tar.gz
patch 7.4.2100v7.4.2100
Problem: "cgn" and "dgn" do not work correctly with a single character match and the replacement includes the searched pattern. (John Beckett) Solution: If the match is found in the wrong column try in the next column. Turn the test into new style. (Christian Brabandt)
Diffstat (limited to 'src/search.c')
-rw-r--r--src/search.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/search.c b/src/search.c
index 5fc682032..1f1ba6a3f 100644
--- a/src/search.c
+++ b/src/search.c
@@ -4719,7 +4719,7 @@ current_search(
}
/*
- * Check if the pattern is one character or zero-width.
+ * Check if the pattern is one character long or zero-width.
* If move is TRUE, check from the beginning of the buffer, else from the
* current cursor position.
* Returns TRUE, FALSE or -1 for failure.
@@ -4734,10 +4734,15 @@ is_one_char(char_u *pattern, int move)
int save_called_emsg = called_emsg;
int flag = 0;
+ if (pattern == NULL)
+ pattern = spats[last_idx].pat;
+
if (search_regcomp(pattern, RE_SEARCH, RE_SEARCH,
SEARCH_KEEP, &regmatch) == FAIL)
return -1;
+ /* init startcol correctly */
+ regmatch.startpos[0].col = -1;
/* move to match */
if (move)
clearpos(&pos)
@@ -4748,22 +4753,30 @@ is_one_char(char_u *pattern, int move)
flag = SEARCH_START;
}
- if (searchit(curwin, curbuf, &pos, FORWARD, spats[last_idx].pat, 1,
+ if (searchit(curwin, curbuf, &pos, FORWARD, pattern, 1,
SEARCH_KEEP + flag, RE_SEARCH, 0, NULL) != FAIL)
{
/* Zero-width pattern should match somewhere, then we can check if
* start and end are in the same position. */
called_emsg = FALSE;
- nmatched = vim_regexec_multi(&regmatch, curwin, curbuf,
- pos.lnum, (colnr_T)0, NULL);
+ do
+ {
+ regmatch.startpos[0].col++;
+ nmatched = vim_regexec_multi(&regmatch, curwin, curbuf,
+ pos.lnum, regmatch.startpos[0].col, NULL);
+ if (!nmatched)
+ break;
+ } while (regmatch.startpos[0].col < pos.col);
if (!called_emsg)
+ {
result = (nmatched != 0
&& regmatch.startpos[0].lnum == regmatch.endpos[0].lnum
&& regmatch.startpos[0].col == regmatch.endpos[0].col);
-
- if (!result && inc(&pos) >= 0 && pos.col == regmatch.endpos[0].col)
- result = TRUE;
+ /* one char width */
+ if (!result && inc(&pos) >= 0 && pos.col == regmatch.endpos[0].col)
+ result = TRUE;
+ }
}
called_emsg |= save_called_emsg;