vim自动跳转到下一行 [英] Automatically go to next line in vim
问题描述
vim 中一个令人沮丧的行为是,当我向右或向左移动光标(分别是l"或h")并且我在行尾或行首时,我的光标不会移动到第一列下一行或上一行的最后一列.
One frustrating behavior in vim is that when i move my cursor right or left (respectively "l" or "h)" and i am at the end or the beginning of the line, my cursor doesn't move to first column of next line or last column of previous line.
有没有办法改变这种行为?
Is there a way to change this behavior ?
推荐答案
您可以使用 whichwrap
设置使 h
和 l
换行围绕各行的开头和结尾:
You can use the whichwrap
setting to make h
and l
wrap around the start and end of individual lines:
set whichwrap+=h,l
但是,Vim 的文档不建议这样做,可能是因为它可能会产生意想不到的副作用(例如破坏插件,或更改常用键映射的工作方式).
However, Vim's documentation recommends against this, probably because it could have unexpected side effects (like breaking plugins, or changing how common key mappings work).
作为替代方案,您可以按照 Matti Virkkunen 的建议进行操作:
As an alternative, you can do what what Matti Virkkunen recommended:
set whichwrap+=<,>,[,]
这使 h
和 l
保留其默认行为,但允许向左和向右箭头键环绕行.(这就是我所做的,而且效果很好.)
This leaves h
and l
with their default behavior, but allows the left and right arrow keys to wrap around lines. (This is what I do, and it works well.)
您可能还想查看 backspace
设置,以控制 Backspace、Delete、Control+W 和 Control+U 在插入模式下的工作方式.我是这样设置的:
You might also want to take a look at the backspace
setting, to control how Backspace, Delete, Control+W, and Control+U work in Insert mode. I set mine like this:
set backspace=indent,eol,start
这让我可以退格几乎所有内容.
That allows me to backspace over pretty much everything.
有关更多信息,请参阅 Vim 帮助中的这些主题:
For more info, see these topics in the Vim help:
:help 'whichwrap
:help 'backspace
这篇关于vim自动跳转到下一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!