Thomas Mellman wrote:
  When moving from buffer to buffer using
  the :bp and :bn commands, vim normally positions the file and cursor
  such that the last line visited is presented in the middle of the
  screen and the cursor is on that line.

  In certain circumstances, however, it does not do this.  In those
  circumstances, when one opens the file, the cursor is indeed placed
  on the last line visited - but that line is positioned at the bottom
  of the window.

  This apparently only happens when syntax is on - but for all (tested)
  syntaxes.

  Now, in particular, this happens if the cursor is positioned on the
  line of the file that falls within a range starting at the window
  height.  The extent of this range appears to be a function of the file
  length - for example, in one case, the window height is 70 lines.  The
  range causing the problem starts at line 70 of the file and - for very
  long files - extents to line 104.  When the cursor is place on line 105,
  moving into the buffer causes the last line to be positioned in the
  middle of the window.  When the cursor is placed on line 104, reentering
  the buffer puts the line at the bottom of the window.

  In this particular case, if the file is longer than 104
  lines but shorter than 139 lines, the event happens anywhere after
  line 69 - but note that only lines 35-104 would be required to display
  line 70 in the middle of the window.

See ":help 'scrolloff'".

Setting 'scrolloff' to a large number (large enough to always be larger than half the value of 'lines') will always keep the cursor line near the middle of the screen, except when it is in the very first or last few lines of the file (e.g., the first line of the file will never start "lower" than the first line of the window).

You could also use z. (zed-fullstop or zee-period depending on your flavour of English) in Normal mode, to move "just once" the cursor line to the middle.


Best regards,
Tony.

Reply via email to