长线水平导航

xra*_*alf 32 navigation vim

我该怎么做:

  1. 向右移动更快,类似于zw(类似于zl但跳到单词)
  2. 只移动光标所在的一条长线.文件的其余部分将保持其位置

我有.vimrc设置set nowrap.那是因为代码看起来比包装线好.但水平导航存在问题.

我注意到了zl(不要混淆l(L)和1)向右移动(zh向左)的快捷方式.

eck*_*kes 45

你试过:help scroll-horizontal吗?

您可以使用映射滚动,例如,向左或向右滚动20个字符:

map <C-L> 20zl " Scroll 20 characters to the right
map <C-H> 20zh " Scroll 20 characters to the left
Run Code Online (Sandbox Code Playgroud)

如果不应用映射,您可以使用zL向右移动视图半宽度并zH向左移动.

关于你问题的第二部分:我不认为这是可能的.您可以拉动整行,将其粘贴到第二个(临时)缓冲区并滚动到那里.只要您只是阅读这些行,这就可以工作.一旦你想要改变某些东西就会出现问题.但这很麻烦......


eli*_*eli 10

添加到其他答案也注意zeand zs,意思是:将屏幕移动到光标的左侧/右侧

下面我粘贴了我的滚动助记符,同时查看hl(和tb)在键盘上的位置以记住屏幕移动的位置

+-------------------------------+
^                               |
|c-e (keep cursor)              |
|H(igh)             zt (top)    |
|                   ^           |
|           ze      |      zs   |
|M(iddle)  zh/zH <--zz--> zl/zL |
|                   |           |
|                   v           |
|L(ow)              zb (bottom) |
|c-y (keep cursor)              |
v                               |
+-------------------------------+
Run Code Online (Sandbox Code Playgroud)


exi*_*xic 7

对于你的问题的第一部分,如评论中所示,zL并且zH是完美的,所以我将在此处添加它。

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.

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


Tar*_*mal 6

使用 shift + 滚动键更快地浏览文本

  • 这不是等同于使用 w 和 b 吗? (5认同)

Bou*_*uty 6

为了更舒适的滚动,类似于插入模式下 ctrl-x,ctrl-e 或 ctrl-x,ctrl-y 触发的滚动模式,以下是我在 vimrc 中添加的内容:

nnoremap <silent> zh :call HorizontalScrollMode('h')<CR>
nnoremap <silent> zl :call HorizontalScrollMode('l')<CR>
nnoremap <silent> zH :call HorizontalScrollMode('H')<CR>
nnoremap <silent> zL :call HorizontalScrollMode('L')<CR>

function! HorizontalScrollMode( call_char )
    if &wrap
        return
    endif

    echohl Title
    let typed_char = a:call_char
    while index( [ 'h', 'l', 'H', 'L' ], typed_char ) != -1
        execute 'normal! z'.typed_char
        redraws
        echon '-- Horizontal scrolling mode (h/l/H/L)'
        let typed_char = nr2char(getchar())
    endwhile
    echohl None | echo '' | redraws
endfunction
Run Code Online (Sandbox Code Playgroud)

这样,您就可以在方便时平滑滚动(使用 h 或 l)或快速滚动(使用 H 或 L),而无需每次都按 z。您只需按一次 z 即可触发“水平滚动模式”,一旦您按任何其他键,该模式就会停止。