contour icon indicating copy to clipboard operation
contour copied to clipboard

yW (yank WORD) not working properly in normal mode

Open ferdinandyb opened this issue 1 year ago • 7 comments
trafficstars

Contour Terminal version

Contour Terminal Emulator 0.4.2.6408-prerelease

Installer source

Github: CI actions

Operating System

Windows 11

Architecture

x86-64

Other Software

No response

Steps to reproduce

Run something like echo "hello 1236", enter normal mode, search for hello and then yank WORD with yW.

Expected Behavior

I would expect "hello" to be yanked.

Actual Behavior

"hello 1" is yanked

Additional notes

No response

ferdinandyb avatar Feb 01 '24 14:02 ferdinandyb

@ferdinandyb I think there's a misunderstanding.

  • w refers to the beginning of the next word (using word delimiters, such as ., ,, :, space, etc..
  • W refers to the beginning of the next word (using whitespace delimiters only)
  • e refers to the end of the current word (delimiters as in w)
  • W refers to the end of the current word (delimiters as in W, i.e. whitespaces only)

So pressing yW will yank everything from the current cursor position to the beginning of the next word whereas yE (and similarily ye) will yank from current position to the end of the current word.

p.s.: I was implementing this based on what I was reading in the vim documentation. However, trying it out right now in vim (and Contour), I noticed a different in vim itself.

vim itself behaves differently in marking the range for yW vs vW. This is a WTF for me. I may have accidentally skipped reading something in the docs that would describe this, but to me that sounds a bit weird. Not sure sure why yW and vW in vim (neovim for me) do operate on a different range, that is, yW excludes the right boundary whereas vW does indeed include it (as we do in Contour, however, for both cases).

So not sure how to process on this ticket. If vim and neovim are doing it that way, then we should adapt of course. Because it's meant to be inspired by vim. It should feel the same then.

christianparpart avatar Feb 02 '24 21:02 christianparpart

@ferdinandyb I think there's a misunderstanding.

  • w refers to the beginning of the next word (using word delimiters, such as ., ,, :, space, etc..
  • W refers to the beginning of the next word (using whitespace delimiters only)
  • e refers to the end of the current word (delimiters as in w)
  • W refers to the end of the current word (delimiters as in W, i.e. whitespaces only)

So pressing yW will yank everything from the current cursor position to the beginning of the next word whereas yE (and similarily ye) will yank from current position to the end of the current word.

p.s.: I was implementing this based on what I was reading in the vim documentation. However, trying it out right now in vim (and Contour), I noticed a different in vim itself.

vim itself behaves differently in marking the range for yW vs vW. This is a WTF for me. I may have accidentally skipped reading something in the docs that would describe this, but to me that sounds a bit weird. Not sure sure why yW and vW in vim (neovim for me) do operate on a different range, that is, yW excludes the right boundary whereas vW does indeed include it (as we do in Contour, however, for both cases).

So not sure how to process on this ticket. If vim and neovim are doing it that way, then we should adapt of course. Because it's meant to be inspired by vim. It should feel the same then.

Ok, so I agree, this is rather confusing ... I did a little search and found this:

https://vi.stackexchange.com/a/24731/25312:

In Vim motions can be either inclusive ("include the rightmost character"), or exclusive ("exclude rightmost character"). w is made exclusive (so you delete exactly four words: "this" "is" "a" "test"). If you want to make it inclusive add :h o_v to the target command: d4vw.

Now, in Visual mode all motions are governed by a global option called :h 'selection'. By default, it's :set selection=inclusive, so ! gets into the visual selection. Add :set selection=exclusive to your vimrc if you don't like it.

I must say, I am a bit confused now, because also W moves to next WORD, but yW yank until the end of the current WORD. I'm confused enough to make a question on stackexchange: https://vi.stackexchange.com/q/44054/25312.

In general I'd say it's best if contour does "default vim", but I would probably like to understand this a bit better now before I say anything :D

ferdinandyb avatar Feb 02 '24 22:02 ferdinandyb

Keep me posted, please. :)

christianparpart avatar Feb 02 '24 22:02 christianparpart

will do :)

ferdinandyb avatar Feb 02 '24 22:02 ferdinandyb

vim itself behaves differently in marking the range for yW vs vW.

evil-mode behaves similar to contour, makes selection until the next word

Yaraslaut avatar Feb 03 '24 07:02 Yaraslaut

The vim question is still ongoing, but two comments came to mind:

  • yanking the first character of the next WORD is a bug either way: neither yW nor vW does that

  • the exact amount of whitespace yanked could be totally irrelevant in many cases, especially if there's a white space stripping mechanism (which I sort of remember contour having?)

ferdinandyb avatar Feb 03 '24 07:02 ferdinandyb

Here's the detailed answer: https://vi.stackexchange.com/a/44056/25312. In short:

  • motions can be inclusive or exclusive, but that only counts after an operator, not when using them to move the cursor in normal mode

  • visual mode always implies inclusive unless the defaults are changed

I guess the question is, how close you want to copy vim. I personally think, it should be as close to vim defaults as possible, but that does entail some additional complexity right now.

ferdinandyb avatar Feb 03 '24 12:02 ferdinandyb