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

mtk*_*mtk 174 vim keyboard-shortcuts vi scrolling

任何更快的导航技巧将光标所在的行放置到

  • 屏幕顶部?
  • 屏幕中央?
  • 屏幕底部?

mtk*_*mtk 240

z<CR>zt 将当前行置于屏幕顶部 ( <CR>== Enter)

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

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

( z<CR>, z.,z-并将光标放在第一个非空白列中。zt, zz, 并将zb光标留在当前列中)

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

  • 你也可以使用`zz`代替`z。` (17认同)
  • 15 年的 vim,我不知道这个方便的小东西!点赞! (3认同)
  • 还有`&lt;行号&gt;z&lt;t | z | b&gt;` 会将行放在 vim 缓冲区的顶部、中心或底部的“行号”处。 (3认同)
  • 我以前没有听说过`z.`。我想我更喜欢按两个不同的键而不是双击。您可以同时进行并行击键,只要它们以正确的顺序着陆,并且击键之间的时间可以很短,这是一个非常快速的选择。`z` 和 `.` 键是彼此的镜像(至少在我的 en-GB 键盘上)。您可以合理地喜欢双击“z”,而且我们有两种选择,这很棒。 (2认同)

Dre*_*kes 25

:help scroll-cursor@mtk 提及的输出。请注意,zz和之间存在差异z.


相对于光标滚动(scroll-cursor)

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

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}
Run Code Online (Sandbox Code Playgroud)

水平滚动(滚动水平)

对于以下四个命令,光标会跟随屏幕。如果光标所在的字符移出屏幕,则光标将移至屏幕上最近的字符。不使用 '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}
Run Code Online (Sandbox Code Playgroud)

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

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}
Run Code Online (Sandbox Code Playgroud)