如何在Vim中将当前行放在屏幕的顶部/中心/底部?


118

任何更快的导航技巧都可以将光标当前所在的行放到

  • 屏幕上方?
  • 屏幕的中心?
  • 屏幕底部?

Answers:


153

z<CR>zt 将当前行放在屏幕顶部(<CR>== Enter

z.zz 将当前行置于屏幕中心

z-zb 将当前行置于屏幕底部

z<CR>z.,和z-把光标在第一非空白列。ztzzzb叶中的光标当前列)

有关在http://vimdoc.sourceforge.net/htmldoc/scroll.html
vim类型中滚动的更多信息:help scroll-cursor


14
你也可以使用zz,而不是z.
evilsoup

2
我没有听说过z.了。我想我更喜欢用两个不同的键来敲击而不是双击。您可以同时进行并行击键,只要它们以正确的顺序降落,并且击中之间的时间会很短,因此这是一个非常快速的选择。在z.键是彼此的镜子(至少我的EN-GB键盘上)。您可以合理地选择双击z,这很不错,我们同时提供了两种选择。
Drew Noakes

15年的vim,我不知道这个方便的小东西!赞!
PnotNP

14

:help scroll-cursor@mtk的输出提及。请注意,zz和之间有区别z.


相对于光标滚动(滚动光标)

以下命令重新定位编辑窗口(您看到的缓冲区的一部分)的位置,同时将光标保持在同一行上:

z<CR>                   Redraw, line [count] at top of window (default
                        cursor line).  Put cursor at first non-blank in the
                        line.

zt                      Like "z<CR>", but leave the cursor in the same
                        column.  {not in Vi}

z{height}<CR>           Redraw, make window {height} lines tall.  This is
                        useful to make the number of lines small when screen
                        updating is very slow.  Cannot make the height more
                        than the physical screen height.

z.                      Redraw, line [count] at center of window (default
                        cursor line).  Put cursor at first non-blank in the
                        line.

zz                      Like "z.", but leave the cursor in the same column.
                        Careful: If caps-lock is on, this command becomes
                        "ZZ": write buffer and exit!  {not in Vi}

z-                      Redraw, line [count] at bottom of window (default
                        cursor line).  Put cursor at first non-blank in the
                        line.

zb                      Like "z-", but leave the cursor in the same column.
                        {not in Vi}

水平滚动(水平滚动)

对于以下四个命令,光标跟随屏幕。如果将光标所在的字符移出屏幕,则光标将移至屏幕上最近的字符。未使用“ sidescroll”的值。

z<Right>    or
zl                      Move the view on the text [count] characters to the
                        right, thus scroll the text [count] characters to the
                        left.  This only works when 'wrap' is off.  {not in
                        Vi}

z<Left>      or
zh                      Move the view on the text [count] characters to the
                        left, thus scroll the text [count] characters to the
                        right.  This only works when 'wrap' is off.  {not in
                        Vi}

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}

对于以下两个命令,光标不会在文本中移动,只有文本会在屏幕上滚动。

zs                      Scroll the text horizontally to position the cursor
                        at the start (left side) of the screen.  This only
                        works when 'wrap' is off.  {not in Vi}

ze                      Scroll the text horizontally to position the cursor
                        at the end (right side) of the screen.  This only
                        works when 'wrap' is off.  {not in Vi}
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.