I would like to map the shift+y
key to move the cursor one position to the right, press the y key and wait for the move command. Similar to the operation of the p key. When used without the shift, the screen pastes the content after the cursor and when used with the shift, pastes before. For example. When I need to copy a word in reverse, I need to do it (l+y+b)
. I would like to do this only with (shift+y+b)
. That is, I would like to copy from the current cursor position and not from the previous position.
1 Answer
When I need to copy a word in reverse, I need to do it
(l+y+b)
. I would like to do this only with(shift+y+b)
. That is, I would like to copy from the current cursor position and not from the previous position.
If you want to copy the current word while the cursor is at the end of it, you can use yvb
, which uses v
as an operator (or a modifier for an operator) to toggle the b
motion from an "exclusive" to an "inclusive" motion.
See :help o_v
:
If the motion already was characterwise, toggle inclusive/exclusive. This can be used to make an exclusive motion inclusive and an inclusive motion exclusive.
(Also :help exclusive
.)
If you want to have the Y
command behave that way, you can simply use:
nnoremap Y yv
But note that while this is useful for yvb
, it might have undesirable side effects on the other situations (such as forward motion e
will now be exclusive, linewise will become characterwise, etc.) It is possible to create a mapping that is more specific (e.g. always do an inclusive motion, etc.) but that starts getting quite complex with all the corner cases that need to be handled.
(My advice: just use the v
operator directly, yvb
is about as easy to type as Yb
and it doesn't require any custom mappings or functions.)
p
key puts. It doesn't copy/yank...but the title says "copy after the cursor". It's a bit confusing. I suggest you adopt the Vim lingo for the sake of accuracy. So you want to put withY
, I guess.:nnoremap Y ly
then. At that point you can enterb
or whatever leftward movement you want and the proper text is yanked including the character the cursor had been over. That's what u want, right? (If it's not right I'll let the next person handle this one...lol)