contour-terminal / contour

Modern C++ Terminal Emulator
http://contour-terminal.org/
Apache License 2.0
2.32k stars 101 forks source link

yW (yank WORD) not working properly in normal mode #1448

Closed ferdinandyb closed 4 days ago

ferdinandyb commented 5 months ago

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

christianparpart commented 5 months ago

@ferdinandyb I think there's a misunderstanding.

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.

ferdinandyb commented 5 months ago

@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

christianparpart commented 5 months ago

Keep me posted, please. :)

ferdinandyb commented 5 months ago

will do :)

Yaraslaut commented 5 months ago

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

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

ferdinandyb commented 5 months ago

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

ferdinandyb commented 5 months ago

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

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.