@@ -339,6 +339,7 @@ win_line(
339339 int change_end = -1 ; // last col of changed area
340340#endif
341341 colnr_T trailcol = MAXCOL ; // start of trailing spaces
342+ colnr_T leadcol = 0 ; // start of leading spaces
342343#ifdef FEAT_LINEBREAK
343344 int need_showbreak = FALSE; // overlong line, skipping first x
344345 // chars
@@ -734,8 +735,9 @@ win_line(
734735
735736 if (wp -> w_p_list )
736737 {
737- if (lcs_space || lcs_trail || lcs_nbsp )
738+ if (lcs_space || lcs_trail || lcs_lead || lcs_nbsp )
738739 extra_check = TRUE;
740+
739741 // find start of trailing whitespace
740742 if (lcs_trail )
741743 {
@@ -744,6 +746,19 @@ win_line(
744746 -- trailcol ;
745747 trailcol += (colnr_T ) (ptr - line );
746748 }
749+ // find end of leading whitespace
750+ if (lcs_lead )
751+ {
752+ leadcol = 0 ;
753+ while (VIM_ISWHITE (ptr [leadcol ]))
754+ ++ leadcol ;
755+ if (ptr [leadcol ] == NUL )
756+ // in a line full of spaces all of them are treated as trailing
757+ leadcol = (colnr_T )0 ;
758+ else
759+ // keep track of the first column not filled with spaces
760+ leadcol += (colnr_T ) (ptr - line ) + 1 ;
761+ }
747762 }
748763
749764 wcr_attr = get_wcr_attr (wp );
@@ -1992,6 +2007,7 @@ win_line(
19922007 || (c == ' '
19932008 && mb_l == 1
19942009 && lcs_space
2010+ && ptr - line >= leadcol
19952011 && ptr - line <= trailcol )))
19962012 {
19972013 c = (c == ' ' ) ? lcs_space : lcs_nbsp ;
@@ -2012,9 +2028,10 @@ win_line(
20122028 mb_utf8 = FALSE;
20132029 }
20142030
2015- if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ' )
2031+ if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ' )
2032+ || (leadcol != 0 && ptr < line + leadcol && c == ' ' ))
20162033 {
2017- c = lcs_trail ;
2034+ c = ( ptr > line + trailcol ) ? lcs_trail : lcs_lead ;
20182035 if (!attr_pri )
20192036 {
20202037 n_attr = 1 ;
0 commit comments