Skip to content

Commit 375e339

Browse files
committed
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Problem: Cannot have a local value for 'scrolloff' and 'sidescrolloff'. (Gary Holloway) Solution: Make 'scrolloff' and 'sidescrolloff' global-local. (mostly by Aron Widforss, closes #3539)
1 parent b3051ce commit 375e339

16 files changed

Lines changed: 177 additions & 67 deletions

File tree

runtime/doc/options.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6590,14 +6590,18 @@ A jump table for the options with a short description can be found at |Q_op|.
65906590

65916591
*'scrolloff'* *'so'*
65926592
'scrolloff' 'so' number (default 0, set to 5 in |defaults.vim|)
6593-
global
6593+
global or local to window |global-local|
65946594
{not in Vi}
65956595
Minimal number of screen lines to keep above and below the cursor.
65966596
This will make some context visible around where you are working. If
65976597
you set it to a very large value (999) the cursor line will always be
65986598
in the middle of the window (except at the start or end of the file or
65996599
when long lines wrap).
6600-
For scrolling horizontally see 'sidescrolloff'.
6600+
After using the local value, go back the global value with one of
6601+
these two: >
6602+
setlocal scrolloff<
6603+
setlocal scrolloff=-1
6604+
< For scrolling horizontally see 'sidescrolloff'.
66016605
NOTE: This option is set to 0 when 'compatible' is set.
66026606

66036607
*'scrollopt'* *'sbo'*
@@ -7152,7 +7156,7 @@ A jump table for the options with a short description can be found at |Q_op|.
71527156

71537157
*'sidescrolloff'* *'siso'*
71547158
'sidescrolloff' 'siso' number (default 0)
7155-
global
7159+
global or local to window |global-local|
71567160
{not in Vi}
71577161
The minimal number of screen columns to keep to the left and to the
71587162
right of the cursor if 'nowrap' is set. Setting this option to a
@@ -7162,7 +7166,11 @@ A jump table for the options with a short description can be found at |Q_op|.
71627166
to a large value (like 999) has the effect of keeping the cursor
71637167
horizontally centered in the window, as long as one does not come too
71647168
close to the beginning of the line.
7165-
NOTE: This option is set to 0 when 'compatible' is set.
7169+
After using the local value, go back the global value with one of
7170+
these two: >
7171+
setlocal sidescrolloff<
7172+
setlocal sidescrolloff=-1
7173+
< NOTE: This option is set to 0 when 'compatible' is set.
71667174

71677175
Example: Try this together with 'sidescroll' and 'listchars' as
71687176
in the following example to never allow the cursor to move

src/edit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ edit(
728728
(int)curwin->w_wcol < mincol - curbuf->b_p_ts
729729
#endif
730730
&& curwin->w_wrow == W_WINROW(curwin)
731-
+ curwin->w_height - 1 - p_so
731+
+ curwin->w_height - 1 - get_scrolloff_value()
732732
&& (curwin->w_cursor.lnum != curwin->w_topline
733733
#ifdef FEAT_DIFF
734734
|| curwin->w_topfill > 0

src/ex_cmds.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3784,6 +3784,7 @@ do_ecmd(
37843784
#endif
37853785
int readfile_flags = 0;
37863786
int did_inc_redrawing_disabled = FALSE;
3787+
long *so_ptr = curwin->w_p_so >= 0 ? &curwin->w_p_so : &p_so;
37873788

37883789
if (eap != NULL)
37893790
command = eap->do_ecmd_cmd;
@@ -4389,12 +4390,12 @@ do_ecmd(
43894390
did_inc_redrawing_disabled = FALSE;
43904391
if (!skip_redraw)
43914392
{
4392-
n = p_so;
4393+
n = *so_ptr;
43934394
if (topline == 0 && command == NULL)
4394-
p_so = 999; /* force cursor halfway the window */
4395+
*so_ptr = 9999; // force cursor halfway the window
43954396
update_topline();
43964397
curwin->w_scbind_pos = curwin->w_topline;
4397-
p_so = n;
4398+
*so_ptr = n;
43984399
redraw_curbuf_later(NOT_VALID); /* redraw this buffer later */
43994400
}
44004401

src/ex_docmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8923,7 +8923,7 @@ ex_syncbind(exarg_T *eap UNUSED)
89238923
{
89248924
if (wp->w_p_scb && wp->w_buffer)
89258925
{
8926-
y = wp->w_buffer->b_ml.ml_line_count - p_so;
8926+
y = wp->w_buffer->b_ml.ml_line_count - get_scrolloff_value();
89278927
if (topline > y)
89288928
topline = y;
89298929
}

src/gui.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4405,7 +4405,7 @@ gui_do_scroll(void)
44054405
#endif
44064406
)
44074407
{
4408-
if (p_so != 0)
4408+
if (get_scrolloff_value() != 0)
44094409
{
44104410
cursor_correct(); /* fix window for 'so' */
44114411
update_topline(); /* avoid up/down jump */

src/misc2.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ leftcol_changed(void)
643643
long lastcol;
644644
colnr_T s, e;
645645
int retval = FALSE;
646+
long siso = get_sidescrolloff_value();
646647

647648
changed_cline_bef_curs();
648649
lastcol = curwin->w_leftcol + curwin->w_width - curwin_col_off() - 1;
@@ -652,15 +653,15 @@ leftcol_changed(void)
652653
* If the cursor is right or left of the screen, move it to last or first
653654
* character.
654655
*/
655-
if (curwin->w_virtcol > (colnr_T)(lastcol - p_siso))
656+
if (curwin->w_virtcol > (colnr_T)(lastcol - siso))
656657
{
657658
retval = TRUE;
658-
coladvance((colnr_T)(lastcol - p_siso));
659+
coladvance((colnr_T)(lastcol - siso));
659660
}
660-
else if (curwin->w_virtcol < curwin->w_leftcol + p_siso)
661+
else if (curwin->w_virtcol < curwin->w_leftcol + siso)
661662
{
662663
retval = TRUE;
663-
(void)coladvance((colnr_T)(curwin->w_leftcol + p_siso));
664+
(void)coladvance((colnr_T)(curwin->w_leftcol + siso));
664665
}
665666

666667
/*

0 commit comments

Comments
 (0)