在vim中可以循环滚动吗? [英] Is circular scrolling possible in vim?

查看:71
本文介绍了在vim中可以循环滚动吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将 vim 配置为移动命令环绕"垂直(或水平)缓冲区?

换句话说,假设我在缓冲区中的第 2 行,处于可视模式.我按 3k.我的光标现在位于缓冲区的最后一行.

或者更简单地说,我的光标在文件的第一行——我按了 k.现在我的光标翻转到文件的最后一行.

抱歉,如果之前有人问过这个问题,但我找不到任何搜索圆形滚动"或环绕滚动"的参考.

解决方案

使用一些 vimscript 黑客可能是可能的,但是使用像 G 这样的动作来提高效率更普遍一个文件和 gg1G 以转到文件的顶部.同样,$ 表示行尾,0 表示行首,^ 表示第一个非空白字符.>

你也可以设置:help whichwrap,它指定移动到行尾时移动到下一行或移动到行首时移动到上一行线.除此之外,我认为没有内置功能可以满足您的要求.您可以使用一些 vimscript 来完成,但它需要将 h、j、k 和 l 重新映射到函数并处理它们是否位于行/文件的末尾/开头.对我来说,这似乎有点矫枉过正,而且相当混乱.

说了这么多,如果你必须……

nnoremap j :call CheckJ()nnoremap k : 调用 CheckK()nnoremap h : 调用 CheckH()nnoremap l : 调用 CheckL()乐趣!检查J()if line('.') == line('$')规范!GG别的规范!j万一尽兴乐趣!检查K()如果行('.')== 1规范!G别的规范!克万一尽兴乐趣!检查H()如果 col('.') == 1规范!$别的规范!H万一尽兴乐趣!检查L()if col('.') == (col('$') - 1)规范!0别的规范!升万一尽兴

Is it possible to configure vim such that a movement command "wraps around" the vertical (or horizontal) buffer?

In other words, assume I'm on line 2 in a buffer, in visual mode. I press 3k. My cursor is now positioned on the last line of the buffer.

Or more simply, my cursor is on the first line of the file -- I press k. Now my cursor flips to the last line of the file.

Apologies if this has been asked before, but I couldn't find any references searching for "circular scrolling" or "wrap-around scrolling".

解决方案

It's probably possible with some vimscript hackery, but it's much more universal to become efficient with motions like G to go to the bottom of a file and gg or 1G or <C-Home> to go to the top of the file. Likewise, $ for the end of a line and 0 for the beginning of the line or ^ for the first non-blank character.

You can also set :help whichwrap, which specifies which keys will move of to the next line when moving past the end of the line or move to the previous line when moving past the beginning of the line. Other then that I don't think there's built in functionality for what you're asking. You can could do it with some vimscript but it would require remapping h,j,k, and l to functions and handling whether they are at the end/beginning of the line/file. To me that seems overkill and rather messy.

All that being said, if you must...

nnoremap j :call CheckJ()<cr>
nnoremap k :call CheckK()<cr>
nnoremap h :call CheckH()<cr>
nnoremap l :call CheckL()<cr>

fun! CheckJ()
   if line('.') == line('$')
      norm! gg
   else
      norm! j
   endif
endfun

fun! CheckK()
   if line('.') == 1
      norm! G
   else
      norm! k
   endif
endfun

fun! CheckH()
   if col('.') == 1
      norm! $
   else
      norm! h
   endif
endfun

fun! CheckL()
   if col('.') == (col('$') - 1)
      norm! 0
   else
      norm! l
   endif
endfun

这篇关于在vim中可以循环滚动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆