繁体   English   中英

Vim有某种语法可以在命令模式下组合命令吗?

[英]Does Vim have a certain syntax to combine commands on command mode?

我在使用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甚至有及物动词和不及物动词!

基本规则非常简单:

{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就像用手指说一种语言,所以您只需要以这种语言思考即可。 您从中获得的不仅仅是速度。

(EndEdit中)

“粘贴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在该主题上写了一篇很棒的文章

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM