in VIM, I understand that we can do a yank till the end of line using y$
but if e.g. 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.
To yank one line, position the cursor anywhere on the line and type yy . Now move the cursor to the line above where you want the yanked line to be put (copied), and type p . A copy of the yanked line will appear in a new line below the cursor.
To copy text, place the cursor in the desired location and press the y key followed by the movement command. Below are some helpful yanking commands: yy - Yank (copy) the current line, including the newline character. 3yy - Yank (copy) three lines, starting from the line where the cursor is positioned.
The vi yy command "yanks" the current line into the vi general buffer. That is, it copies the line for you to put into the file immediately. The vi p and P commands "put" the line back into the file just after (p) or just before (P) the line on which the cursor is resting.
If you want to select the entire line in a file, press V. Now when you press k or j to go up and down, vim will select the entire line above and below your cursor. Finally, you can select text in columns by pressing ctrl+v and moving up or down the block.
0y$$ - copy the line without line break and move cursor back to the end
Making it a visual selection and then yanking that includes the character under the cursor:
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With