Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Y do the same thing as yy?

Tags:

vim

I've been using vim for several months now and I've gotten used to using C and D to change and delete everything from the cursor to the end of the line.

Consider the line below where the cursor is on the 'b' in 'bar':

foo.bar("hello world")

Hitting D at this point will yield:

foo.

While hitting C will do the same plus start insert mode with the cursor after the period.

However, pressing Y doesn't do the intuitively similar thing (copying everything from the cursor to the end of the line). Instead, it copies the entire line (just like yy).

How do I make Y copy the characters from the cursor to the end of the line instead of copying the entire line like yy?

like image 861
advait Avatar asked Aug 18 '10 21:08

advait


2 Answers

From this configuration:

" make Y effect to end of line instead of whole line
map Y y$

I suspect the default behaviour is simply due to some historical inconsistency.

like image 60
Brian Agnew Avatar answered Nov 16 '22 02:11

Brian Agnew


nmap Y y$

Does that do what you want?

EDIT

The reason why Y does the same thing as yy probably has something to do with this:

{Visual}["x]y           Yank the highlighted text [into register x] (for
                        {Visual} see |Visual-mode|).  {not in Vi}

                                                        *v_Y*
{Visual}["x]Y           Yank the highlighted lines [into register x] (for
                        {Visual} see |Visual-mode|).  {not in Vi}

Y is meant to act on lines, y is meant to act on individual characters?

like image 38
Jamie Wong Avatar answered Nov 16 '22 03:11

Jamie Wong