长线水平导航

发布于 2024-11-07 04:11:47 字数 295 浏览 0 评论 0原文

我该如何执行以下操作:

  1. 更快地向右移动,例如 zw (类似于 zl 但跳转到单词)
  2. 仅移动光标所在的一长行。文件的其余部分将保留在其位置,

我有 .vimrc 设置 set nowrap。这是因为代码看起来比换行更好。但水平导航存在问题。

我注意到 zl (不要将 l (L) 与 1 混淆)快捷方式向右移动(zh 向左移动)。

How can I do the following:

  1. shift faster to the right, something like zw (analogy to zl but jump on words)
  2. shift only the one long line where is the cursor. The rest of the file will remain in its position

I have .vimrc settings set nowrap. That's because the code looks nicer than wrapped lines. But there is a problem with horizontal navigation.

I noticed that zl (don't confuse l (L) with 1) shortcut which shifts to the right (zh to the left).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

笑脸一如从前 2024-11-14 04:11:48

您是否尝试过 :help roll-horizo​​ntal

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

map <C-L> 20zl " Scroll 20 characters to the right
map <C-H> 20zh " Scroll 20 characters to the left

在不应用映射的情况下,您可以使用 zL 将视图向右移动半个屏幕宽度,然后 zH 向左执行。

关于你问题的第二部分:我认为这是不可能的。您可以拉出整行,将其粘贴到第二个(临时)缓冲区中并滚动到那里。只要你只是阅读台词,这就会起作用。一旦你想改变什么,问题就会出现。但实在是太麻烦了...

Did you try :help scroll-horizontal?

You could use a mapping to scroll, for example, 20 characters to the left or to the right:

map <C-L> 20zl " Scroll 20 characters to the right
map <C-H> 20zh " Scroll 20 characters to the left

Without applying a mapping, you could use zL to move the view a half screenwidth to the right and zH to do it to the left.

Regarding the second part of your question: I don't think that this is possible. You could yank the whole line, paste it into a second (scratch) buffer and scroll there. This would work as long as you're just reading the lines. Problems will arise as soon as you want to change something. But it's quite cumbersome...

少钕鈤記 2024-11-14 04:11:48

添加到其他答案还要注意 zezs,意思是:将屏幕移动到

下面光标的左/右我粘贴我的助记词进行滚动
还要查看键盘上 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                               |
+-------------------------------+

adding to other answers also pay attention to ze and zs, meaning: move screen to the left/right of the cursor

below I paste my mnemonic for scrolling
also look at the position of h and l (and t and b) on the keyboard to remember where the screen is moving

+-------------------------------+
^                               |
|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                               |
+-------------------------------+
拧巴小姐 2024-11-14 04:11:48

使用 Shift + 滚动键可以更快地浏览文本

Use shift + scrolling keys to move faster through text

违心° 2024-11-14 04:11:48

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

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.

For the first part of your question, as in the comments, zL and zH are perfect, so I'll add this here.

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.
赢得她心 2024-11-14 04:11:48

为了更舒适的滚动,类似于插入模式下 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

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

For a more comfortable scrolling, similar to the scrolling mode triggered by ctrl-x,ctrl-e or ctrl-x,ctrl-y in insert mode, here is what I added in my 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

This way, you can scroll smoothly (with h or l) or rapidly (with H or L) at your convenience without pressing z again and again each time. You just press z once in order to trigger the "horizontal scrolling mode", which stop as soon as you press any other key.

忆依然 2024-11-14 04:11:48

使用 w 向前滚动,使用 b 向后滚动。这可能是最简单的方法。

Use w to scroll forward and b to scroll backward. This is probably the easiest way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文