Vim: Moving the cursor to somewhere outside of the viewport should center the cursor vertically

Created on 15 Aug 2018  路  7Comments  路  Source: VSCodeVim/Vim

Describe the bug
A couple of examples of the situation described in the title:

  • When jumping to a mark outside of the viewport, the cursor line is placed at either the first or second from last line in the viewport.
  • When searching for a string with / and the next occurrence is outside of the viewport, the cursor line is placed at either the first or second from last line in the viewport.

To Reproduce
Steps to reproduce the behavior:

  1. Set a mark at line x in a file with ma.
  2. Navigate to another part of the file such that the line x is outside of the viewport.
  3. Jump to the mark with 'a.

Expected behavior
The cursor line x should be vertically centered.

Screenshots
marks

Environment (please complete the following information):

  • Extension (VsCodeVim) version: 0.16.0
  • VSCode version: 1.25.1
  • OS: Windows 10
kinbug

Most helpful comment

The above commit (4434) seems to behave unexpectedly around heavily folded code. If I'm traversing lines (simple cursor movements like jk) in a non-folded section of code, the cursor works just fine. When I'm doing the same amidst many folds, cursor navigation behaves almost like a scrollOffset is set (keeping the cursor in the center always).

All 7 comments

Checking if there's an update or a workaround for this bug. For example, a keybinding that might center the screen after the search.

Looks like zz is the binding I was looking for :)
Still would be nice if the cursor was centered by default after the search.

@naseer I'm not sure what zz is supposed to do but in Vim the M key will move the cursor to the vertical middle of the screen.

EDIT:
Seems like zz is more inline with what you were talking about. Centering the word at the middle, not just the cursor.

Digging into this a bit more. In vim, if you put the cursor at the top of the viewport with H (scrolloff=0), 14k does not center the viewport around the new cursor position, but 15k does.
It takes 18j at the bottom to center, but I think that's because of the status line, etc.

Seems going to marks behaves the same way. I think we should center if the cursor is 15 or more lines outside the viewport, which should also prevent issues such as #2998

The above commit (4434) seems to behave unexpectedly around heavily folded code. If I'm traversing lines (simple cursor movements like jk) in a non-folded section of code, the cursor works just fine. When I'm doing the same amidst many folds, cursor navigation behaves almost like a scrollOffset is set (keeping the cursor in the center always).

@pnalchajian Please file a separate issue

Same issue that @pnalchajian mentioned. Not sure if he has created a new issue for this or not.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cckowin picture cckowin  路  3Comments

triztian picture triztian  路  3Comments

orn688 picture orn688  路  3Comments

lucastheisen picture lucastheisen  路  3Comments

waltiam picture waltiam  路  3Comments