goto
goto copied to clipboard
"^A" is inserted at old cursor position in vi mode
If bash is in vi mode (set -o vi), then whenever the I jump to a new character a "^A" is inserted after the old cursor position.
Using bash version 3.2.20(1)-release (x86_64-pc-linux-gnu)
Does it work correctly for you without vi mode ? I want to make sure this not due to the bash version.
Yup, works perfectly without vi mode. It looks like it's the \key1
binding to \C-a
which goes to the beginning of the line in emacs mode, but just inserts a ^A
in vi mode.
Things seem to work well if I just get rid of the ^A whenever we're in vi mode, e.g:
# Key bindings. Before executing the main function, place the cursor at the begeninng of the command line (\key1).
if [[ ${SHELLOPTS} =~ (^|:)"vi"(:|$) ]]; then
bind '"\key1":""'
else
bind '"\key1":"\C-a"'
fi
The only thing that sucks here is that we bind when we source the plugin, which means that if we turn on vi mode later then we're out of luck.
Hmm, I need to think about it. I'm not sure 100% that removing the "\C-a" will actually resolve the issue. I did it (placed the cursor at the beginning) to fix a displaying bug for some cases, but maybe it's no longer needed in vi mode. I'll try to do more tests.
Indeed, removing it will not work properly. You can try your snippet with a command that takes 2 lines or more for example. You will see that things gonna be messed up. So placing the cursor at the beginning before executing the main function is mandatory, but not sure how to do it in vi mode. I'll try to figure out a way to fix that, but if you have any suggestion, don't hesitate :)