[Tutor] OT (probably): How to change default tab key value to 4 spaces in GNOME Terminal?

boB Stepp robertvstepp at gmail.com
Sun Apr 26 15:36:04 EDT 2020


On Sun, Apr 26, 2020 at 4:02 AM Peter Otten <__peter__ at web.de> wrote:

> With readline you can do
>
> import readline
> readline.parse_and_bind("TAB: '    '")
>
> but then you lose tab-completion (which you don't seem to use anyway).

Hah!  Silly boB was not even aware that he had access to it!  See my
response to Alan.

> An alternative might be to keep autocompletion and bind 4-space indent to
> another key:
>
> readline.parse_and_bind("TAB: complete")
> readline.parse_and_bind("C-h: '    '")  # Control-h

Well, Peter, you have opened up quite the educational experience for
me last night and today!  While looking at the docs for readline I
found a link to the GNU Readline Library
(https://tiswww.cwru.edu/php/chet/readline/rluserman.html#SEC9).  I
have no idea why my searching yesterday did not bring up a link to
this.  I used to be aware of some of the things mentioned, like the
Emacs keybindings some of which I routinely used.  And I recall (quite
vaguely) that there was a way to have the terminal use vi keybindings
instead, but I did not know the way ... now I do.

And I was totally unaware of the Python readline and rlcompleter
libraries and what they do to make the Python interpreter do its
stuff.  So now I must rethink what I have been doing.  An obvious
first step would seem to be using vi keybindings in the terminal.  I'm
not sure yet how the interpreter would then behave.  Hopefully it
won't mind and give me the behaviors I expect from vi keybindings.
But I won't know for sure until I try it (or investigate the source).
In vi's insert mode C-t inserts a tab.  Now how do I get that to
expand to 4 spaces without interfering with tab completion.  On to
your next response!

-- 
boB


More information about the Tutor mailing list