How do you keep X number of characters in vim?

I know that 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 to another location.

I am lazy and rather just withstand 5 characters, so I do not need to undo the cut.

How can i do this?

+44
vim
Sep 22 '11 at 19:55
source share
3 answers

Yank supports standard move commands. Use y 5 l (<- - lowercase L)

And if you want to print 5 characters back, use y 5 h .

Now, if you feel lazy, rearrange this particular sequence into a key combination, for example:

 :nnoremap <Cl> y5l 

In this case, "yank 5 to the right" is displayed on Ctrl + l (lowercase L).




If you want, you can also use Space instead of l to carry characters forward (examples: y Space for one character or 5 y Space for 5). It may seem to some people that it will be faster or easier than hitting l .

+66
Sep 22 '11 at 19:57
source share

This complements the voithos answer:

You can also use 5 y Space or y 5 Space (ty @hauleth for suggestion)

This is useful to me, especially when I want to pull out only one character:

y space

It’s easier (at least for me) to find and press Space than l .

+8
Dec 31 '15 at 8:37
source share

y5 will do it. yy yanks strings, y yanks characters.

-7
Sep 22 '11 at 19:58
source share



All Articles