I know I can cut 5 characters in vim by typing 5x
, and I often use this to copy and paste text by doing 5xu
then pasting them somewhere else.
I am lazy and would rather just yank the 5 characters so I don't have to undo the cut action.
How can I do this?
To place the yanked line in a new line above the cursor, type P . The yy command works well with a count: to yank 11 lines, for example, just type 11yy . Eleven lines, counting down from the cursor, will be yanked, and vi indicates this with a message at the bottom of the screen: 11 lines yanked .
The simplest and fastest way is to use: : % y + and then go over to Google Docs (or wherever) and paste. Explanation: % to refer the next command to work on all the lines. y to yank those lines.
Press v to begin character-based visual selection, or V to select whole lines, or Ctrl-v or Ctrl-q to select a block. Move the cursor to the end of the text to be cut/copied. While selecting text, you can perform searches and other advanced movement. Press d (delete) to cut, or y (yank) to copy.
Yank supports standard movement commands. Use y5l (<- that's a lowercase L)
And if you want to yank 5 characters backwards, use y5h.
Now, if you're feeling really lazy, remap this particular sequence to a key-combination, like so:
:nnoremap <C-l> y5l
In this case, "yank 5 to the right" gets mapped to Ctrl+L (lowercase L).
If you'd like, you can also use Space instead of L to yank characters in the forward direction (examples: ySpace for a single character or 5ySpace for 5). Some people may find it to be quicker or easier than hitting L.
This is complementing the answer of voithos:
You can also use 5ySpace or y5Space (ty @hauleth for suggestion)
This is useful for me especially when I want to yank just one character:
ySpace
Is easier (for me at least) to find and hit Space than l.
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