Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vi mode word extension from end of words doesn't work #328

Open
bkerin opened this issue May 26, 2023 · 2 comments
Open

vi mode word extension from end of words doesn't work #328

bkerin opened this issue May 26, 2023 · 2 comments

Comments

@bkerin
Copy link
Contributor

bkerin commented May 26, 2023

GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu) [Linux Mint 20.3]
ble.sh, version 0.4.0-devel4+0906fd9 (noarch) [git 2.25.1, GNU Make 4.3, GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.2.0)]
bash-completion, version 2.10 (hash:b6da7f7edfc1c3c5196c86c81fb05fce96f83c03, 74550 bytes) (noarch)
locale: LANG=en_US.UTF-8
terminal: TERM=xterm-256color wcwidth=12.1-west/15.0-2+ri, vte:6003 (65;6003;1)

If you put this on the command line:

 # foo bar

then position the cursor on the first o in foo, then type 'vliw', ble.sh fails to extend the visual selection to include the space as vi does.

I think the problem is an off-by-one in ble/keymap:vi/text-object/word.extend-forward (it's hidden by the regex except when the cursor ends on the last char of a wordafter direction indication). I think the fix is:

diff --git a/lib/keymap.vi.sh b/lib/keymap.vi.sh
old mode 100644
new mode 100755
index 25e9430..1219e64
--- a/lib/keymap.vi.sh
+++ b/lib/keymap.vi.sh
@@ -4478,9 +4478,9 @@ function ble/keymap:vi/text-object/word.extend-forward {
       [[ ${_ble_edit_str:end:1} == $'\n' ]] && ((end++))
     fi
 
-    [[ ${_ble_edit_str:end} =~ $rex_unit ]] || return 1
+    [[ ${_ble_edit_str:((end+1))} =~ $rex_unit ]] || return 1
     rematch=$BASH_REMATCH
-    ((end+=${#rematch}))
+    ((end+=${#rematch}+1))
 
     # Note: aw に対する正規表現では二重改行を読むが後退する。
     [[ $type == a* && $rematch == *$'\n\n' ]] && ((end--))
@bkerin
Copy link
Contributor Author

bkerin commented May 26, 2023

ok trying again on the patch:

diff --git a/lib/keymap.vi.sh b/lib/keymap.vi.sh
old mode 100644
new mode 100755
index 25e9430..1219e64
--- a/lib/keymap.vi.sh
+++ b/lib/keymap.vi.sh
@@ -4478,9 +4478,9 @@ function ble/keymap:vi/text-object/word.extend-forward {
       [[ ${_ble_edit_str:end:1} == $'\n' ]] && ((end++))
     fi
 
-    [[ ${_ble_edit_str:end} =~ $rex_unit ]] || return 1
+    [[ ${_ble_edit_str:((end+1))} =~ $rex_unit ]] || return 1
     rematch=$BASH_REMATCH
-    ((end+=${#rematch}))
+    ((end+=${#rematch}+1))
 
     # Note: aw に対する正規表現では二重改行を読むが後退する。
     [[ $type == a* && $rematch == *$'\n\n' ]] && ((end--))

@akinomyoga
Copy link
Owner

Thank you! I'll take a look later.

By the way, you can re-edit a comment by the button on the top right corner:

image

This time, I edited your original comment by adding ```diff ... ```. (Note: The owner of the repository can also edit the comments of any people).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants