akinomyoga / ble.sh

Bash Line Editor―a line editor written in pure Bash with syntax highlighting, auto suggestions, vim modes, etc. for Bash interactive sessions.
BSD 3-Clause "New" or "Revised" License
2.58k stars 82 forks source link

yy copies a newline in front of the line #414

Closed raffaem closed 7 months ago

raffaem commented 7 months ago
GNU bash, version 5.2.26(1)-release (x86_64-pc-linux-gnu) [Arch Linux]
ble.sh, version 0.4.0-devel4+98a2ae15 (noarch) [git 2.43.1, GNU Make 4.4.1, GNU Awk 5.3.0, API 4.0, PMA Avon 8-g1, (GNU MPFR 4.2.1, GNU MP 6.3.0)]
bash-preexec (wezterm.sh), (hash:1cc83f86c72a217a0c56bf4f4e5d9a8834142817, 20228 bytes) (noarch)
starship, version 1.17.1 (rustc 1.75.0 (82e1608df 2023-12-21) (Arch Linux rust 1:1.75.0-1), 2024-01-03 07:54:53 +00:00)
zoxide, version 0.9.2 (/usr/bin/zoxide)
atuin, version 18.0.1 (/usr/bin/atuin)
locale: LANG=en_US.UTF-8 LC_TIME=en_DK.UTF-8
terminal: TERM=xterm-256color wcwidth=15.0-west/15.1-2+ri, wezterm:20220408 (1;277;0)

When you press yy in normal mode, the line is copied with a new line in front of it

To reproduce

  1. Enter insert mode
  2. Type echo "hello"
  3. Enter normal mode
  4. Type yy
  5. Press carriage return
  6. Enter normal mode
  7. Type p
  8. \necho "hello" will be pasted
akinomyoga commented 7 months ago

That is the correct behavior.

What inserts the newline is not yy, but p. For the linewise range, p pastes the lines after the current line. This is exactly Vim's behavior. I haven't thought about it consciously until now, but after some trials, I feel the current behavior is still natural even in the shell. Though, it's interesting to see some people seem to expect a different behavior.

If you want to paste the line before the current line, you need to use P. Or if you expect p to always behave like P, you might consider rebinding it as ble-bind -m vi_nmap -f p vi_nmap/paste-before.

raffaem commented 7 months ago

oh right, my bad.

Thanks for looking into this!