Skip to main content
added 226 characters in body
Source Link
Bananach
  • 524
  • 5
  • 16
if searchString != ""
    let newBG = search(searchString) != 0 ? "green" : "red"
    execute("hi StatusLine ctermfg=" . newBG)
endif

Explanation: It seems vim's search function is the culprit (note that the function in question continuously runs vim's search to update the color of the statusline). It automatically uses the previous search term if nothing is entered. This can be tested in a clean vim:

  1. vim --clean
  2. ia<CR>b<CR>a<esc> (enter three lines, each with a single letter, end at third line)
  3. /a<CR> (jumps to first line)
  4. /<CR> (jumps to third line, because it uses the search term a)

WARNING: This introduces another problem: The hlsearch-highlight skips one match now. What is highlighted before pressing Enter is not the closed match (which is what the search actually ends up presenting at pressing Enter).

if searchString != ""
    let newBG = search(searchString) != 0 ? "green" : "red"
    execute("hi StatusLine ctermfg=" . newBG)
endif

Explanation: It seems vim's search function is the culprit (note that the function in question continuously runs vim's search to update the color of the statusline). It automatically uses the previous search term if nothing is entered. This can be tested in a clean vim:

  1. vim --clean
  2. ia<CR>b<CR>a<esc> (enter three lines, each with a single letter, end at third line)
  3. /a<CR> (jumps to first line)
  4. /<CR> (jumps to third line, because it uses the search term a)
if searchString != ""
    let newBG = search(searchString) != 0 ? "green" : "red"
    execute("hi StatusLine ctermfg=" . newBG)
endif

Explanation: It seems vim's search function is the culprit (note that the function in question continuously runs vim's search to update the color of the statusline). It automatically uses the previous search term if nothing is entered. This can be tested in a clean vim:

  1. vim --clean
  2. ia<CR>b<CR>a<esc> (enter three lines, each with a single letter, end at third line)
  3. /a<CR> (jumps to first line)
  4. /<CR> (jumps to third line, because it uses the search term a)

WARNING: This introduces another problem: The hlsearch-highlight skips one match now. What is highlighted before pressing Enter is not the closed match (which is what the search actually ends up presenting at pressing Enter).

added 1 character in body
Source Link
D. Ben Knoble
  • 27.7k
  • 3
  • 31
  • 68
if searchString != ""
    let newBG = search(searchString) != 0 ? "green" : "red"
    execute("hi StatusLine ctermfg=" . newBG)
endif

Explanation: It seems vim's search function is the culprit (note that the function in question continuously runs vim's search to update the color of the statusline). It automatically uses the previous search term if nothing is entered. This can be tested in a clean vim:

  1. vim --clean
  2. `iabaia<CR>b<CR>a<esc> (enter three lines, each with a single letter, end at third line)
  3. /a<CR> (jumps to first line)
  4. /<CR> (jumps to third line, because it uses the search term a)
if searchString != ""
    let newBG = search(searchString) != 0 ? "green" : "red"
    execute("hi StatusLine ctermfg=" . newBG)
endif

Explanation: It seems vim's search function is the culprit (note that the function in question continuously runs vim's search to update the color of the statusline). It automatically uses the previous search term if nothing is entered. This can be tested in a clean vim:

  1. vim --clean
  2. `iaba (enter three lines, each with a single letter, end at third line)
  3. /a<CR> (jumps to first line)
  4. /<CR> (jumps to third line, because it uses the search term a)
if searchString != ""
    let newBG = search(searchString) != 0 ? "green" : "red"
    execute("hi StatusLine ctermfg=" . newBG)
endif

Explanation: It seems vim's search function is the culprit (note that the function in question continuously runs vim's search to update the color of the statusline). It automatically uses the previous search term if nothing is entered. This can be tested in a clean vim:

  1. vim --clean
  2. ia<CR>b<CR>a<esc> (enter three lines, each with a single letter, end at third line)
  3. /a<CR> (jumps to first line)
  4. /<CR> (jumps to third line, because it uses the search term a)
added 498 characters in body
Source Link
Bananach
  • 524
  • 5
  • 16
if searchString != ""
    let newBG = search(searchString) != 0 ? "green" : "red"
    execute("hi StatusLine ctermfg=" . newBG)
endif

Explanation: It seems vim's search function is the culprit (note that the function in question continuously runs vim's search to update the color of the statusline). It automatically uses the previous search term if nothing is entered. This can be tested in a clean vim:

  1. vim --clean
  2. `iaba (enter three lines, each with a single letter, end at third line)
  3. /a<CR> (jumps to first line)
  4. /<CR> (jumps to third line, because it uses the search term a)
if searchString != ""
    let newBG = search(searchString) != 0 ? "green" : "red"
    execute("hi StatusLine ctermfg=" . newBG)
endif
if searchString != ""
    let newBG = search(searchString) != 0 ? "green" : "red"
    execute("hi StatusLine ctermfg=" . newBG)
endif

Explanation: It seems vim's search function is the culprit (note that the function in question continuously runs vim's search to update the color of the statusline). It automatically uses the previous search term if nothing is entered. This can be tested in a clean vim:

  1. vim --clean
  2. `iaba (enter three lines, each with a single letter, end at third line)
  3. /a<CR> (jumps to first line)
  4. /<CR> (jumps to third line, because it uses the search term a)
Source Link
Bananach
  • 524
  • 5
  • 16
Loading