当输入大量文本时,光标会被推到屏幕底部。我经常必须退出插入模式才能键入zz,这样Vim就可以将光标所在的行集中起来。我想要一些更自动的东西:例如,如果光标侵入一个阈值(例如,在“屏幕中心的线”下面5-8行),Vim将直接zz,而不退出插入模式。
这可能会扰乱打字过程,但由于我会打字,我的眼睛会盯着屏幕,看到正在发生什么事情。我认为退出插入模式更具有破坏性。
是否有支持此用例的配置选项或插件?
发布于 2018-04-25 16:08:06
通过将“scrolloff”选项设置为一个大值,您可以将光标的行保持为中心:
set scrolloff=999“帮助”页面中的“scrolloff”描述:
Minimal number of screen lines to keep above and below the cursor.
This will make some context visible around where you are working. If
you set it to a very large value (999) the cursor line will always be
in the middle of the window (except at the start or end of the file or
when long lines wrap).发布于 2018-04-25 17:01:21
在此区域键入任何字符或进入插入模式(添加到.vimrc)时,当光标位于缓冲区的最后1/3范围内时,将自动设置以下垂直中心游标:
augroup autoCenter
autocmd!
autocmd InsertCharPre,InsertEnter * if (winline() * 3 >= (winheight(0) * 2))
\| norm! zz
\| endif
augroup END:h autocmd-events并添加可能需要触发对中的任何其他事件。
发布于 2021-02-22 17:15:03
我偶然发现了这样的解决方案:https://vi.stackexchange.com/a/26055/31046
在插入模式下,这对我来说很好:
inoremap <CR> <C-\><C-O><C-E><CR>
inoremap <BS> <BS><C-O>zz
inoremap <right> <right><C-O>zz
inoremap <left> <left><C-O>zz
inoremap <up> <up><C-O>zz
inoremap <down> <down><C-O>zz在插入模式下,我只需要单击backspace或任何箭头键即可生效。
https://stackoverflow.com/questions/50026385
复制相似问题