简体   繁体   English

Vim - 从当前光标位置开始直到行首

[英]Vim - yank from current cursor position till beginning of line

in VIM, I understand that we can do a yank till the end of line using y$ but if eg my text is abcdefg and my cursor is at 'g' and I enter y^ the line will be copy without the g . 在VIM中,我知道我们可以使用y$直到行结束,但是如果我的文本是abcdefg并且我的光标在'g'并且我输入y^那么该行将是没有g的复制。 My idea is to copy the whole line without the line break, any similar action will do. 我的想法是在没有换行符的情况下复制整行,任何类似的操作都可以。

0y $$ - 复制没有换行符的行并将光标移回到结尾

使其成为一个视觉选择然后yanking包括光标下的字符:

v0y

If all the characters are indeed together and conform to a "vim sentence", you could use visual selection for the sentence object. 如果所有字符确实在一起并且符合“vim句子”,则可以对sentence对象使用视觉选择。 A sentence in this case would match abcdefg even if that is not starting at the beginning of a line and it will not include the line ending: 在这种情况下, sentence将匹配abcdefg即使它不是从行的开头开始,也不包括行结尾:

visy

If you want to include trailing whitespace you would use a instead of i (mnemonic for "inside"): 如果你想包含尾随空格,你可以使用a而不是i (“inside”的助记符):

vasy

The only problem with this approach (which may be what you do not want) is that it will not include leading whitespace. 这种方法的唯一问题(可能是你不想要的)是它不包括前导空格。 So if you have something like: 所以如果你有类似的东西:

    abcdefg

The selection will not include the leading chunk of whitespace, just abcdefg . 选择将不包括前面的空白块,只是abcdefg

Turns out yanking till end of line is a thing you'll find yourself doing quite often. 结果是y till直到行尾是你会发现自己经常做的事情。 As such, the following mapping is quite popular. 因此,以下映射非常流行。

noremap Y y$

It's so popular, it's even listed under :h Y ! 它如此受欢迎,它甚至列在:h Y

If you use this mapping, the answer to your question would be 0Y 如果您使用此映射,您的问题的答案将是0Y

0yg_

is another option. 是另一种选择。

But visual mode is better: 但视觉模式更好:

v0y
v^y

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

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