Repository: neovim/neovim
File: src/nvim/move.c (C)

Code before:
        && wp->w_skipcol > 0
        && wp->w_wcol >= wp->w_skipcol) {
      // Deduct by multiples of width2.  This allows the long line wrapping
      // formula below to correctly calculate the w_wcol value when wrapping.
      if (wp->w_skipcol <= width1) {
        wp->w_wcol -= width2;
      } else {
        wp->w_wcol -= width2 * (((wp->w_skipcol - width1) / width2) + 1);
      }

      did_sub_skipcol = true;
    }

    // long line wrapping, adjust wp->w_wrow
    if (wp->w_wcol >= wp->w_view_width) {
      // this same formula is used in validate_cursor_col()
      n = (wp->w_wcol - wp->w_view_width) / width2 + 1;
      wp->w_wcol -= n * width2;
      wp->w_wrow += n;
    }
  } else if (may_scroll
             && !wp->w_cline_folded) {
    // If the terminal buffer is being resized, let w_leftcol be 0
    if (bt_terminal(wp->w_buffer) && terminal_may_resize(wp->w_buffer->terminal)) {
      if (wp->w_leftcol != 0) {
        wp->w_leftcol = 0;
        win_check_anchored_floats(wp);
        // screen has to be redrawn with new wp->w_leftcol
        redraw_later(wp, UPD_NOT_VALID);
      }
    } else {
      // No line wrapping: compute wp->w_leftcol if scrolling is on and line
      // is not folded.
      // If scrolling is off, wp->w_leftcol is assumed to be 0

      // If Cursor is left of the screen, scroll rightwards.
      // If Cursor is right of the screen, scroll leftwards
      // If we get closer to the edge than 'sidescrolloff', scroll a little
      // extra
      int siso = get_sidescrolloff_value(wp);
      int off_left = startcol - wp->w_leftcol - siso;
      int off_right = endcol - wp->w_leftcol - wp->w_view_width + siso + 1;

      if (off_left < 0 || off_right > 0) {
        int diff = (off_left < 0) ? -off_left : off_right;

        // When far off or not enough room on either side, put cursor in
        // middle of window.
        int new_leftcol;
        if (p_ss == 0 || diff >= width1 / 2 || off_right >= off_left) {
          new_leftcol = wp->w_wcol - extra - width1 / 2;

Review comment (suggestion):
could avoid the extra nesting, and diff churn, with something like:

```c
} else if (!bt_terminal(wp->w_buffer) && may_scroll && !wp->w_cline_folded) {
  // ...
} else if (bt_terminal(wp->w_buffer) && may_scroll && !wp->w_cline_folded) {
  // ...
```

Code after:
    width2 = width1 + win_col_off2(wp);

    // skip columns that are not visible
    if (wp->w_cursor.lnum == wp->w_topline
        && wp->w_skipcol > 0
        && wp->w_wcol >= wp->w_skipcol) {
      // Deduct by multiples of width2.  This allows the long line wrapping
      // formula below to correctly calculate the w_wcol value when wrapping.
      if (wp->w_skipcol <= width1) {
        wp->w_wcol -= width2;
      } else {
        wp->w_wcol -= width2 * (((wp->w_skipcol - width1) / width2) + 1);
      }

      did_sub_skipcol = true;
    }

    // long line wrapping, adjust wp->w_wrow
    if (wp->w_wcol >= wp->w_view_width) {
      // this same formula is used in validate_cursor_col()
      n = (wp->w_wcol - wp->w_view_width) / width2 + 1;
      wp->w_wcol -= n * width2;
      wp->w_wrow += n;
    }
  } else if (may_scroll
             && !wp->w_cline_folded) {
    // No line wrapping: compute wp->w_leftcol if scrolling is on and line
    // is not folded.
    // If scrolling is off, wp->w_leftcol is assumed to be 0

    // If Cursor is left of the screen, scroll rightwards.
    // If Cursor is right of the screen, scroll leftwards
    // If we get closer to the edge than 'sidescrolloff', scroll a little
    // extra
    int siso = get_sidescrolloff_value(wp);
    int off_left = startcol - wp->w_leftcol - siso;
    int off_right = endcol - wp->w_leftcol - wp->w_view_width + siso + 1;
    if (off_left < 0 || off_right > 0) {
      int diff = (off_left < 0) ? -off_left : off_right;

      // When far off or not enough room on either side, put cursor in
      // middle of window.
      int new_leftcol;
      if (p_ss == 0 || diff >= width1 / 2 || off_right >= off_left) {
        new_leftcol = wp->w_wcol - extra - width1 / 2;
      } else {
        if (diff < p_ss) {
          assert(p_ss <= INT_MAX);
          diff = (int)p_ss;
        }
        if (off_left < 0) {