简体   繁体   English

命令 y3s 在 Vim 中以普通模式复制三行

[英]the command y3s to copy three lines in Normal Mode in Vim

According to Vim's Verb, Noun, and Modifier logic the command y3s should potentially copy three sentences, but in my version of Vim it doesn't do that.根据 Vim 的动词、名词和修饰符逻辑,命令y3s应该可能复制三个句子,但在我的 Vim 版本中它没有这样做。 I am wondering if there is a reason for it.我想知道是否有原因。 Looking up online it seems like there are other ways to copy a specific number of sentences, but I am curious why this approach doesn't work.在网上查找似乎还有其他方法可以复制特定数量的句子,但我很好奇为什么这种方法不起作用。 Thanks!谢谢!

Several misconceptions here.这里有几个误解。 First, there is a difference between motions and text objects .首先,动作文本对象之间存在差异。

A motion ( :help navigation ) is a command that changes the position of the cursor: l for right, j for down, ) for sentence forward, 2Fx backward to before-previous x in the same line, /foo/e+2<CR> forward to 2 characters after the end of next foo , w start of next word.动作( :help navigation )是改变光标位置的命令: l表示右, j表示下, )表示句子向前, 2Fx向后到同一行中的前一个x/foo/e+2<CR>前进到下一个foo结束后的 2 个字符, w下一个单词的开始。 Commands whose argument is a motion operate on the text span from the current position to the new motion-specified position.参数为动作的命令对从当前位置到新动作指定位置的文本范围进行操作。 dw thus deletes from current position to the start of the next word. dw因此从当前位置删除到下一个单词的开头。

A text object ( :help text-objects ) specifies a semantic unit of text;文本对象( :help text-objects )指定文本的语义单元; it typically consists of two keypresses, the first of which is i (inside, inner) or a (a, an, around).它通常由两个按键组成,第一个是i (内部,内部)或a (a,an,周围)。 i" inside double quotes, a( around parenthesis, is inner sentence (ie without spaces around it), 2aw twice a word. Thus daw delete around this word (including the space), or simpler, delete a word. i"在双引号内, a(括号周围, is内部句子(即它周围没有空格), 2aw一个单词两次。因此daw删除这个单词周围(包括空格),或者更简单,删除一个单词。

The difference is clear: if you are in the middle of a word, eg Some peng|uins fly (with | representing the cursor), dw gives you Some peng|fly (deleting from cursor to start of the next word), while daw gives you Some |fly (deleting the entire word penguins , along with the next space because of the "around" modifier).区别很明显:如果你在一个单词的中间,例如Some peng|uins fly (用|代表光标), dw给你Some peng|fly (从光标删除到下一个单词的开头),而daw给你Some |fly (删除整个单词penguins ,以及由于“around”修饰符的下一个空格)。 diw would give you Some | fly diw会给你Some | fly Some | fly (not including the space into the deletion). Some | fly (不包括空间进入删除)。

As you'll note, "sentence" has a different mapping in text motions ( ( sentence backward, ) sentence forward) and text objects ( is inner sentence, as a sentence).正如您将注意到的,“句子”在文本运动( (句子向后, )句子向前)和文本对象( is内部句子, as句子)中具有不同的映射。 Meanwhile, ( as a text object, equivalently to ) and b , is everything inside, or around, parentheses;同时, (作为文本对象,相当于)b ,是括号内或括号周围的所有内容; and s as a text motion does not exist by default.s作为文本动作默认不存在。

Thus, y2s is not a known mapping, since you are deleting by motion (no i or a ), and there is no motion s ;因此, y2s不是已知映射,因为您是按运动删除(没有ia ),并且没有运动s it will not do anything.它不会做任何事情。

You can use y2) , which would yank about a sentence and a half (ie from cursor to the start of the second next sentence);您可以使用y2) ,这将猛拉大约一个半句子(即从光标到下一个第二个句子的开头); or you can use y2as to yank the current sentence and the next sentence and a space after it;或者您可以使用y2as猛拉当前句子和下一个句子以及它后面的空格; or y2is for the same except without that last space;y2is是相同的,除了没有最后一个空格; but you cannot use y2s .但你不能使用y2s (You can also write all of those as 2y) , 2yas , 2yis .) (您也可以将所有这些都写为2y)2yas2yis 。)

In y2y (or equivalently 2yy ), the second y is the duplication of the operator.y2y (或等效的2yy )中,第二个y是运算符的重复项。 It is almost a rule in Vim that the motion equal to the operator is a line: yy yank a line, dd delete a line, gqgq (or gqq ) reformat a line, == filter a line, gugu (or guu ) uppercase a line etc. The reason is a simple convenience: lines are what we operate on most frequently, and it's hard to make a faster incantation than the same key pressed twice.在 Vim 中,等于操作符的动作是一行,这几乎是一个规则: yy猛拉一行, dd删除一行, gqgq (或gqq )重新格式化一行, ==过滤一行, gugu (或guu )大写 a行等。原因很简单:行是我们最常操作的内容,并且很难比按两次相同的键更快地进行咒语。 Thus, the second y by itself does not have a meaning: it signifies that the first y is working on lines (thus y2y or 2yy yank two lines).因此,第二个y本身没有意义:它表示第一个y正在线上工作(因此y2y2yy猛拉两条线)。

The whole :help motion.txt page is a very useful read, I heartily recommend it.整个:help motion.txt页面非常有用,我衷心推荐它。

If you want to copy 3 lines, you should do y3y , not y3s .如果你想复制 3 行,你应该做y3y ,而不是y3s y stands for Yank or copy. y代表扬克或复制。

Update,更新,

@Amadan 's answer has more explanation and also for why y3y works. @Amadan 的回答有更多解释以及为什么y3y有效。

Simpley 3Y will do, where Y will yank a line and 3 will repeat it 3 times. Simpley 3Y会做,其中Y将拉一条线, 3将重复 3 次。 In Vim there are no sentences, only lines, words, and characters.在 Vim 中没有句子,只有行、词和字符。

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

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