3

The copy-paste functions in vim seem a bit inconsistent to me. The commands yy, dd and cc yank/delete the whole line. The commands D and C delete from the cursor to the end of line, but Y yanks the whole line instead. I want Y to work the same as D and C. So I put the following line in my .vimrc:

nmap Y y$

It doesn't seem to work though. My first idea was that it is because of some plugin interfering. I tried to put the command to both the beginning and the end of my .vimrc, but nothing helped. However, if I type the command manually (not from .vimrc), it works. Why is this? How do I make this work?

petersohn
  • 11,292
  • 13
  • 61
  • 98
  • 2
    with that line at the end of your vimrc, what's the output of `:verbose map Y`? btw, consider using `nnoremap Y y$` – Kent Nov 03 '14 at 20:42

2 Answers2

5

Your vimrc is loaded before plugins are loaded, so this doesn't rule out that a plugin is overriding it. Placing .vim files in .vim/after/ will be loaded after plugins so you could test that theory that way if you want to avoid the route of removing your plugins one-by-one.

As mentioned by Kent, you should really consider using nnoremap over nmap.

FDinoff
  • 30,689
  • 5
  • 75
  • 96
Andrew Haust
  • 356
  • 2
  • 12
  • Actually, the key was overwritten by the YankRing plugin. Mapping it from `.vim/after` worked, but I really need `nmap` instead of `nnoremap` because when I use `y` from within the command I want YankRing to actually catch it. – petersohn Nov 07 '14 at 21:12
  • The YankRing docs mention that you can add the function: function! YRRunAfterMaps() nnoremap Y :YRYankCount 'y$' endfunction to avoid YankRing taking precedence over the mapping. – piro Jun 04 '15 at 17:33
  • Regarding @Kent's comment/suggestion: differences between `nmap`, `nnoremap`, and more are covered in [this answer](https://stackoverflow.com/a/3776182/6411857). You can also `:h nnoremap` to learn more. – DroidClicketyClacker Jun 12 '21 at 00:05
2

Pasting a new answer as code is not formatted in the comment of the answer above.

If the conflict is YankRing you can use:

function! YRRunAfterMaps()
    nnoremap Y   :<C-U>YRYankCount 'y$'<CR>
endfunction
nnoremap Y y$

source: :help yankring-custom-maps

piro
  • 13,378
  • 5
  • 34
  • 38