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

标签 vim

是否可以使用 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/

相关文章:

c - 如何从 VIM 运行 C 程序?

vim - Unite.vim file_rec/async

ruby - 当我将 ruby​​ 更新到 2.0.0-p0 时,我的 vim 无法工作

未找到 Vim map 模式

vim - 如何获得窗口的唯一标识符?

vim - Vim 的自动右括号

regex - VIM - 如何粘贴没有特殊字符的搜索寄存器?

ubuntu - 如何在 .vimrc 中检测 vim 与 gvim

vim - 在gvim中,是否可以有多行文件选项卡?

vim - 在 Vim 中调整/对齐错误格式输出