如何在不移动光标的情况下左右移动屏幕或水平居中?

时间:2017-05-11 12:38:58

标签: vim

例如在线粘贴我的窗口显示文档的最右边部分(列> 80)。

将光标留在当前位置时,如何将屏幕水平居中。或者,我可以将屏幕进一步向左移动半个屏幕宽度,避免固定数字,例如, 44zh

虽然标题是非特定的,但所有答案仅涉及向上/向下移动: How to move screen without moving cursor in Vim?

3 个答案:

答案 0 :(得分:3)

我不知道将屏幕水平居中放在光标周围,但只要向左/右移动屏幕半屏,请尝试此操作(来自:help scroll-horizontal

zL          Move the view on the text half a screenwidth to the
            right, thus scroll the text half a screenwidth to the
            left.  This only works when 'wrap' is off.  {not in
            Vi}


zH          Move the view on the text half a screenwidth to the
            left, thus scroll the text half a screenwidth to the
            right.  This only works when 'wrap' is off.  {not in
            Vi}

答案 1 :(得分:1)

我正在使用的一个不错的配置选项是sidescrolloff,与scrolloff相反。

我目前正在我的 .vimrc 中同时使用它们,这是我不能没有的设置。当然,您可以根据需要增加/减少偏移量。我猜这取决于您正在处理的文档类型:)

set scrolloff=20       " keep 20 lines visible above and below cursor at all times                                                                        
set sidescrolloff=30   " keep 30 columns visible left and right of the cursor at all times

下面来自Vim的一些信息:帮助

  

下滚:要保留在光标上方和下方的最小屏幕行数。           这样可以使您在工作的地方看到一些上下文。

     

侧向滚动:要保留在左侧和左侧的最小屏幕列数           如果设置了'nowrap',则在光标右侧。

答案 2 :(得分:0)

您也可以使用:

zlzh仅移动一个字符