gpt4 book ai didi

vim - 在 Vim 中插入两行新行?

转载 作者:行者123 更新时间:2023-12-04 22:28:48 25 4
gpt4 key购买 nike

是否可以使用 Vim 命令执行此操作?

[] = 光标正常模式

[ = 光标插入模式


Text []


Text

[


Text []


[

Text

最佳答案

我已经更改了 [count] o 的行为/O使用以下映射。我认为这可以满足您的要求:

" o/O                   Start insert mode with [count] blank lines.
" The default behavior repeats the insertion [count]
" times, which is not so useful.
function! s:NewLineInsertExpr( isUndoCount, command )
if ! v:count
return a:command
endif

let l:reverse = { 'o': 'O', 'O' : 'o' }
" First insert a temporary '$' marker at the next line (which is necessary
" to keep the indent from the current line), then insert <count> empty lines
" in between. Finally, go back to the previously inserted temporary '$' and
" enter insert mode by substituting this character.
" Note: <C-\><C-n> prevents a move back into insert mode when triggered via
" |i_CTRL-O|.
return (a:isUndoCount && v:count ? "\<C-\>\<C-n>" : '') .
\ a:command . "$\<Esc>m`" .
\ v:count . l:reverse[a:command] . "\<Esc>" .
\ 'g``"_s'
endfunction
nnoremap <silent> <expr> o <SID>NewLineInsertExpr(1, 'o')
nnoremap <silent> <expr> O <SID>NewLineInsertExpr(1, 'O')

关于vim - 在 Vim 中插入两行新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27819225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com