【问题标题】:Does Vim have a certain syntax to combine commands on command mode?Vim 是否有特定的语法可以在命令模式下组合命令?
【发布时间】:2014-04-06 14:27:39
【问题描述】:

我在使用 vim 时注意到了一些语法

例如

[<motion>]<operator><motion>

e.g.

<gg><d><G> // delete from the top of file to the bottom of file
    <d><G> // delete from the current line to the bottom of file

为了

<operator><operator>

e.g.

<y><y> // inline copy
<d><d> // inline delete
<>><>> // inline right-indent

好的,类似这些。

对于语法或组合命令的方式,我只知道一些模式。

对我来说,我认为有很多方法可以在 vim 上组合命令,这对我来说看起来太乱了

我觉得 Vim 应该有命令基础。

我想知道

vim 是否有特定的语法来组合命令?

你能给我更多关于这方面的信息吗?

【问题讨论】:

    标签: vim syntax command vi


    【解决方案1】:

    将动作视为句子,将命令视为该句子中的单词:动词、宾语、介词短语、根据语法(与大多数语法一样)分组在该句子中的修饰语,但总体上很有意义。见鬼,Vim 甚至还有及物动词和不及物动词!

    基本规则真的很简单:

    {count}operator{motion}
    {count}operator{text-object}
    

    如果您对要执行的操作有一个清晰的概念,那么使用 Vim 的语言几乎没有摩擦。

    “剪切这行代码块并将其粘贴到函数签名下方。”可能变成:

    dip                           " cut this paragraph
    ?func<CR>                     " move the cursor to the first func above
    p                             " paste
    

    而不是令人难以置信的复杂:

    <Home>                        " move the cursor to the start of the line
    <Shift><Down><Down><Down>     " select the block I want to move
    <C-x>                         " to cut the selection
    <Up><Up><Up><Up><Up><Up><Up>  " move up to the target
    <End>                         " move the cursor at the end of the line
    <CR>                          " open a new line 
    <C-v>                         " (finally) paste those lines
    

    (编辑)

    上面的例子很好地说明了 Vim 编辑模型的美妙之处:在你的想法和实际做的事情之间几乎没有“差异”。在更传统的编辑器中,“增量”可能巨大,因为执行给定任务所需的所有完全不相关的步骤。因为使用 Vim 就像用手指说一种语言,你只需要思考那种语言就可以提高效率。您从中获得的不仅仅是速度。

    (结束)

    “粘贴 6 次。”变得很棒:

    6p                            " paste 6 times
    

    代替:

    <C-v><C-v><C-v><C-v><C-v><C-v>
    

    其他有趣的规则:

    • 小写动作 (bwe) 适用于以关键字字符分隔的 words
    • 大写动作 (BWE) 适用于以空格分隔的 WORDS
    • 一些大写操作符 (FTP) 的工作方式与小写操作符类似,但方向相反,
    • 一些大写操作符 (IA) 的工作方式与小写操作符类似,但在行的末端,
    • 其他一些大写运算符 (YCDVS),如双小写运算符 (yyddcc) 是非常常见的 operator{motion} 句子的快捷方式...

    Glts 已就此主题写了an awesome article

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-07
      • 2012-08-18
      • 2023-01-08
      • 2020-07-10
      • 1970-01-01
      • 2017-02-15
      • 2018-10-14
      相关资源
      最近更新 更多