Vim是否具有在命令模式下组合命令的特定语法?

时间:2014-04-06 14:27:39

标签: vim syntax command vi

当我使用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是否有一定的语法来组合命令?

您能否向我提供更多相关信息?

1 个答案:

答案 0 :(得分:4)

将句子和命令视为句子中的单词:动词,对象,介词短语,根据语法分组的修饰符(与大多数语法一样)具有其角落案例但总体上有很多意义。地狱,Vim甚至有传递和不及物动词!

基本规则非常简单:

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

如果您对要执行的操作有清楚的认识,那么使用Vim的语言几乎不会摩擦。

&#34;剪切这一行并将其粘贴到功能签名下方。&#34;可能会成为:

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编辑模型的美妙之处:很少甚至没有&#34; delta&#34;在你的想法和你实际做的事情之间。在更传统的编辑中,那就是&#34; delta&#34;由于执行给定任务所需的所有完全不相关的步骤,因此可以巨大。因为使用Vim就像用手指说一种语言一样,你只需要用那种语言思考就可以有效。你从中获得的不仅仅是速度。

(EndEdit中)

&#34;粘贴6次。&#34;变得很棒:

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