1

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.

8
  • @BLayer not really. this will copy the rest of the line. I would like to copy from the current cursor position, not the previous one. I will improve my question. – Lucas Martins Soares Nov 19 '20 at 23:04
  • @BLayer it's done. – Lucas Martins Soares Nov 19 '20 at 23:08
  • 1
    The 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 with Y, I guess. – B Layer Nov 19 '20 at 23:09
  • has it become clearer now? @BLayer – Lucas Martins Soares Nov 19 '20 at 23:15
  • 1
    Just :nnoremap Y ly then. At that point you can enter b 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) – B Layer Nov 19 '20 at 23:36
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.