Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixing <right arrow> in bash vi input mode. Cannot type beyond last character

I'm trying to use vi mode in bash. via the .inputrc (on OSX):

set editing-mode vi

In vi insert mode, the right arrow key moves the cursor to the right, but it stops on the last character in the line. If the cursor is past the end of the line, it moves the cursor to the left. So, in sum, the farthest right you can go is to the last character in the line.

$ cd /usr/locl/bin
# Move the cursor to the middle of the line, and fix something there
$ cd /usr/local/bin
# Now move the cursor back to the end, and write a character (/)
$ cd /usr/local/bi/n

As shown above this means you cannot edit the end of the line without going into command mode (and using 'a').

I found an article which seems to indicate the version of readline/bash might be the problem. However I used brew to upgrade bash (GNU bash, version 4.3.42), and even tried to install and link readline (6.3.8), as recommend by that site. But no luck. Its possible the upgrade was done incorrectly.

This means I'm looking for one of the following:

  • The proper way to upgrade bash and readline in OSX terminal
  • A way to check the versions of bash/readline that OSX is actually using
  • Another fix for this bug (somehow passing in the virtualedit=onemore option in the inputrc)
  • Indications that the latest versions of readline might have re-introduced the bug, and solutions.
  • Also: if theres a similar thing with editrc

Note: I'm looking to make readline in bash act near identical to the default (for others who periodically use my terminal), but allow me to use vim mode. This means I don't need workarounds, but fixes.

like image 235
Saevon Avatar asked Oct 31 '22 01:10

Saevon


1 Answers

Answer here: https://unix.stackexchange.com/a/222506/198846

Apparently it's a bug in the bash version shipped with OSX (3.2), it's fixed in 4.3 according to that answer. Use bash --version to check your bash version.

To fix, update bash, e.g.

macports: sudo port install bash

brew: brew install bash

Once installed bash --version will show it's updated (assuming standard brew/macports paths at the start of your $PATH)

You then have to change your default login shell (in System Preferences->Users & Groups->right click your user->advanced options->login shell) to the path of the new bash:

(default) macports: /opt/local/bin/bash

(default) brew: /usr/local/bin/bash

Changing the default login shell step is required even if which bash shows the macports/brew one.

All credit to the answer linked above.

like image 59
JobJob Avatar answered Nov 15 '22 07:11

JobJob