gpt4 book ai didi

vim - 在 Vim 的空行上使用 "cc"、 "S"或 "]p"命令时,自动缩进失败

转载 作者:行者123 更新时间:2023-12-03 22:56:24 24 4
gpt4 key购买 nike

如果我尝试 ccS当光标(下图 |)在下面时
位置:

public function blah()
{
var i = 0;
|
i++
return i;
}

它停留在第一列而不是在字母下方移动 vvar .粘贴 ]p也从第 1 列开始粘贴。

我的设置(在 MacVim 中)是: autoindent , smartindent , nocindent , 和 indentexpr= ,如果这有帮助。

根据以下 SO 问题,应该可以正确缩进:
  • Vim: Smart indent when entering insert mode on blank line?
  • Vim: Indent current (blank) line and insert
  • Autoindent in vim always empty the line if there are only whitespace in it, can I change that?

  • 在上一篇博文中, @trVoldemort有同样的问题(见第二个答案的评论)。

    最佳答案

    从手册:

                                *cc*
    ["x]cc Delete [count] lines [into register x] and start
    insert |linewise|. If 'autoindent' is on, preserve
    the indent of the first line.

    *S*
    ["x]S Delete [count] lines [into register x] and start
    insert. Synonym for "cc" |linewise|.

    由于您要删除的行没有缩进,因此会保留该缩进。
    如果在该行中插入空格,则 $ 将光标放在此处:
    public function blah() {
    var i = 0;
    |
    i++
    return i;
    }

    然后按0回到第一列,最后按S,就会得到想要的结果。

    我意识到这只能解释当前的行为,但不能直接解决您的问题,但我不确定是否有一种干净的方法来解决您的问题。我倾向于建议做这样的映射:
    :nnoremap cc ddko
    :nnoremap S ddko

    这些 dd 删除当前行,k 向上移动到上一行,o 在下一行打开输入(使用 smartindent 提供缩进)。

    关于vim - 在 Vim 的空行上使用 "cc"、 "S"或 "]p"命令时,自动缩进失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7136701/

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