简体   繁体   中英

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 . 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. 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:

visy

If you want to include trailing whitespace you would use a instead of i (mnemonic for "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 .

Turns out yanking till end of line is a thing you'll find yourself doing quite often. As such, the following mapping is quite popular.

noremap Y y$

It's so popular, it's even listed under :h Y !

If you use this mapping, the answer to your question would be 0Y

0yg_

is another option.

But visual mode is better:

v0y
v^y

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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