In inputrc, making backward-word and forward-word work

If you have any suggestions or ideas about improving Salix, here's the place to post them.
Atticus
Posts: 11
Joined: 1. Mar 2010, 19:26

In inputrc, making backward-word and forward-word work

Post by Atticus »

I'm not sure if this is just me, but I've gotten used to pressing Ctrl-left-click and Ctrl-right-click in the terminal to move backward and forward a word, rather than just a letter. However, in Salix OS, when I press Ctrl-left-click, it just enters the letters "%5D" over and over. I found a solution here which basically says:

Code: Select all

Add the following lines to ~/.inputrc:

"\e[1;5C": forward-word   # ctrl + right
"\e[1;5D": backward-word  # ctrl + left 
then to reload, type:

Code: Select all

bind -f ~/.inputrc
I'm not sure if it was just me having this problem, but I figured I would report my issue and the solution I found and maybe this will get into the next version of Salix OS.

Thanks!
User avatar
gapan
Salix Wizard
Posts: 6241
Joined: 6. Jun 2009, 17:40

Re: In inputrc, making backward-word and forward-word work

Post by gapan »

I'm sorry, but where does that happen? Where do you see it?
Image
Image
User avatar
thenktor
Salix Wizard
Posts: 2426
Joined: 6. Jun 2009, 14:47
Location: Franconia
Contact:

Re: In inputrc, making backward-word and forward-word work

Post by thenktor »

This happens in xterm or other terminal emulators (with TERM=xterm). Press [CTRL]+[Left] or [CTRL]+[Right]. The default inputrc in Slackware has this:

Code: Select all

"\eOd": backward-word
"\eOc": forward-word
I have no idea which keys this escape sequences refer to.

To get the escape sequence of a key (or key combination) type [CTRL]+[v] followed by the key:
[CTRL]+[v] [CTRL]+[Left] results in ^[[1;5D.

So if you want to use [CTRL]+[Left] for backward-word you have to add to inputrc:

Code: Select all

"\e[1;5D": backward-word  # ctrl + left
;)
Image
burnCDDA (burns audio CDs)
geBIERt (German beer blog)
User avatar
gapan
Salix Wizard
Posts: 6241
Joined: 6. Jun 2009, 17:40

Re: In inputrc, making backward-word and forward-word work

Post by gapan »

but he's talking about ctrl-left-click and ctrl-right-click. Certainly the only thing that makes a click is the mouse?
Image
Image
User avatar
mimosa
Salix Warrior
Posts: 3311
Joined: 25. May 2010, 17:02
Contact:

Re: In inputrc, making backward-word and forward-word work

Post by mimosa »

Well, there's ratclick :twisted:

Also I believe you can tell bash to use vim-like editing ... yes, here's a link to info about that and more:

http://blog.sanctum.geek.nz/command-line-editing/

The 'fc' thing looks very handy, though beware (I just tried it and) if you exit your editor without saving (:q in vim) the previous command is executed unchanged.

EDIT

To exit without changing the command, and without executing it either (like ctrl-c in bash) do in vim

Code: Select all

:cq
(from a comment on a post about fc)
Last edited by mimosa on 27. Jun 2013, 11:02, edited 1 time in total.
User avatar
thenktor
Salix Wizard
Posts: 2426
Joined: 6. Jun 2009, 14:47
Location: Franconia
Contact:

Re: In inputrc, making backward-word and forward-word work

Post by thenktor »

gapan wrote:but he's talking about ctrl-left-click and ctrl-right-click. Certainly the only thing that makes a click is the mouse?
I don't think he really means click. He means the keys. Everything else does not make sense for me ;)
Image
burnCDDA (burns audio CDs)
geBIERt (German beer blog)
Atticus
Posts: 11
Joined: 1. Mar 2010, 19:26

Re: In inputrc, making backward-word and forward-word work

Post by Atticus »

Hi guys, sorry I meant Ctrl+leftbutton and Ctrl+rightbutton, not mouse clicks.
User avatar
gapan
Salix Wizard
Posts: 6241
Joined: 6. Jun 2009, 17:40

Re: In inputrc, making backward-word and forward-word work

Post by gapan »

Atticus wrote:Hi guys, sorry I meant Ctrl+leftbutton and Ctrl+rightbutton, not mouse clicks.
OK, so did you really try this solution or are you just posting what you found?

BTW, the \eOd and \eOc codes are for ctrl-left and ctrl-right keys, it's just only that they work in rxvt.
Image
Image
User avatar
thenktor
Salix Wizard
Posts: 2426
Joined: 6. Jun 2009, 14:47
Location: Franconia
Contact:

Re: In inputrc, making backward-word and forward-word work

Post by thenktor »

gapan wrote:BTW, the \eOd and \eOc codes are for ctrl-left and ctrl-right keys, it's just only that they work in rxvt.
So the correct inputrc entry would be:

Code: Select all

$if term=rxvt-unicode
"\eOd": backward-word     # ctrl + left 
"\eOc": forward-word      # ctrl + right
$else
"\e[1;5D": backward-word  # ctrl + left 
"\e[1;5C": forward-word   # ctrl + right
$endif
There are probably a lot of other differences in rxvt. See the insane inputrc of OpenSUSE: http://pastebin.com/g6e6NyL9 ;)
Image
burnCDDA (burns audio CDs)
geBIERt (German beer blog)
Atticus
Posts: 11
Joined: 1. Mar 2010, 19:26

Re: In inputrc, making backward-word and forward-word work

Post by Atticus »

gapan wrote:
Atticus wrote:Hi guys, sorry I meant Ctrl+leftbutton and Ctrl+rightbutton, not mouse clicks.
OK, so did you really try this solution or are you just posting what you found?

BTW, the \eOd and \eOc codes are for ctrl-left and ctrl-right keys, it's just only that they work in rxvt.
I have been using the solution I posted and it has worked great for me. I'm on Salix 14.0 with Xfce using Xfce Terminal. Unfortunately, I don't have much experience with ~/.inputrc and how it works with other terminal emulators so I can't really offer you a well engineered solution beyond what I've posted.

My hope is that even if this suggestion isn't enacted in Salix then at least people who have this issue will find a solution here.
Post Reply