patch 8.2.2518: 'listchars' should be window-local

Problem:    'listchars' should be window-local.
Solution:   Make 'listchars' global-local. (Yegappan Lakshmanan, Marco Hinz,
            closes #5206, closes #7850)
diff --git a/src/optionstr.c b/src/optionstr.c
index c8a5b0c..a1cbe26 100644
--- a/src/optionstr.c
+++ b/src/optionstr.c
@@ -862,10 +862,24 @@
     {
 	if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
 	    errmsg = e_invarg;
-	else if (set_chars_option(&p_lcs) != NULL)
-	    errmsg = _("E834: Conflicts with value of 'listchars'");
-	else if (set_chars_option(&p_fcs) != NULL)
+	else if (set_chars_option(curwin, &p_fcs) != NULL)
 	    errmsg = _("E835: Conflicts with value of 'fillchars'");
+	else
+	{
+	    tabpage_T	*tp;
+	    win_T	*wp;
+
+	    FOR_ALL_TAB_WINDOWS(tp, wp)
+	    {
+		if (set_chars_option(wp, &wp->w_p_lcs) != NULL)
+		{
+		    errmsg = _("E834: Conflicts with value of 'listchars'");
+		    goto ambw_end;
+		}
+	    }
+	}
+ambw_end:
+	{}
     }
 
     // 'background'
@@ -1292,16 +1306,37 @@
 	}
     }
 
-    // 'listchars'
+    // global 'listchars'
     else if (varp == &p_lcs)
     {
-	errmsg = set_chars_option(varp);
+	errmsg = set_chars_option(curwin, varp);
+	if (errmsg == NULL)
+	{
+	    tabpage_T	*tp;
+	    win_T		*wp;
+
+	    // The current window is set to use the global 'listchars' value.
+	    // So clear the window-local value.
+	    if (!(opt_flags & OPT_GLOBAL))
+		clear_string_option(&curwin->w_p_lcs);
+	    FOR_ALL_TAB_WINDOWS(tp, wp)
+	    {
+		errmsg = set_chars_option(wp, &wp->w_p_lcs);
+		if (errmsg)
+		    break;
+	    }
+	    redraw_all_later(NOT_VALID);
+	}
     }
 
+    // local 'listchars'
+    else if (varp == &curwin->w_p_lcs)
+	errmsg = set_chars_option(curwin, varp);
+
     // 'fillchars'
     else if (varp == &p_fcs)
     {
-	errmsg = set_chars_option(varp);
+	errmsg = set_chars_option(curwin, varp);
     }
 
 #ifdef FEAT_CMDWIN