Linux-like ^A (ctrl-a) in Cygwin

1

I've installed the latest Cygwin on Win10. Out of habit on *nix, I find myself hitting ^A to go to the beginning of the current line, but the default (hopefully modifiable) behaviour is that it selects the whole text contents of the console (which IMHO is inconsistent because other Emacs-like shortcuts, like ^E, ^D, ^K etc work as expected).

Is there a way to change this and make ^A perform the "right action" and take me to the beginning of the line?

David

Posted 2018-07-16T18:47:22.677

Reputation: 13

It should be noted that ^A doing select-all is consistent with other Windows (non-console) apps. – Jeff Zeitlin – 2018-07-16T19:10:54.950

@JeffZeitlin OK, so "right action" may have been subjective... hence the double quotes :-) – David – 2018-07-16T19:22:37.773

Answers

0

This is the domain of inputrc and the bind builtin.

Specifically, your binding would look like:

"\C-a": beginning-of-line

or

bind '"\C-a":beginning-of-line'

This is the default btw, so in your system, it must be redefined somewhere.


As per Bash Reference Manual: Readline Init File Syntax, "Key bindings" section, you can run bind -p to dump all current bindings and see if it's redefined.

If it is, use procmon to see what files bash reads at startup.

If it's not, it's not Bash that's doing that. Most probably, your terminal emulator -- check its settings for any key bindings and such.

ivan_pozdeev

Posted 2018-07-16T18:47:22.677

Reputation: 1 468

Thanks for the answer. I was very hopeful but then I tried both to add the binding to my .inputrc (and reopen a terminal window) or to call the bind command from the command line, ^A still performs the selection :-|. Any subtleties to adding this? I know I haven't changed it myself, and AFAIK my Cygwin installation is as standard as it gets, I haven't been fooling around with it. ^A does work in Emacs while in the console though, it's really just bash that doesn't get it. – David – 2018-07-16T19:15:23.773

@David The linked page says that you can call bind -p to print all of the bindings. That'll show if it's redefined. See https://unix.stackexchange.com/questions/334382/find-out-what-scripts-are-being-run-by-bash-on-startup to find out where.

– ivan_pozdeev – 2018-07-16T19:27:52.210

Right so bind -p shows ^A is bound to beginning-of-line (actually it was even without my adding it to .inputrc). Still it won't do what I want :-\ Thanks for the help though! – David – 2018-07-16T19:37:34.160

@David see the update – ivan_pozdeev – 2018-07-16T19:37:59.693

OK, so since I haven't seen any other binding of \C-a' inbind -p`, that means that the original/first binding should apply, and since it doesn't then it most probably is Cygwin's fault, right? – David – 2018-07-16T19:41:40.357

@David "If it's not, it's not Bash that's doing that. Probably your terminal emulator." Which emulator are you using? Consult its settings. Also check if there's a similar effect in regular cmd (normally, it should print ^A) -- if there is, you have some background program installed that's intercepting keystrokes. – ivan_pozdeev – 2018-07-16T19:44:42.133

@David I have Cygwin with default settings here, and nothing like you're describing happens. So it's definitely not "Cygwin's fault" -- it's either some non-default settings, or other software on your system. – ivan_pozdeev – 2018-07-16T19:48:16.223

1Got it. Simply had to uncheck "Enable Ctrl key shortcuts" in the console's properties... Feeling a bit stupid now. Again thanks for the help! I'd upvote you but I'm afraid I'm too new here. – David – 2018-07-16T19:52:46.410

@David you can click the check mark to accept the answer that resolves your problem.

– ivan_pozdeev – 2018-07-16T19:54:22.083

I will but (no offense meant of course) the answer you provided, although very instructive, was actually not the solution to the problem. I would mark your comment "Edit the console's settings" with the actual action taken as the answer if I could. You may want to add that to your answer for other users with the same problem to quickly find the solution. – David – 2018-07-16T19:58:07.493

@David In an answer, I can only use whatever information you provided in the question. I had no way to know it was mintty's settings specifically, it could as well be something else entirely -- and for the next guy, it can as well be. I'm okay with updating the answer with your specific resolution as one possible cause, but that's not strictly necessary since I upvoted your comment which will make it stand out for the next reader. – ivan_pozdeev – 2018-07-16T20:23:05.587

@David that said, there's no "Enable Ctrl key shortcuts" in either mintty or cmd settings on my machine (Win7), so I've no idea which terminal emulator you're using and can't say anything about the option you're speaking of. So only added general advice. – ivan_pozdeev – 2018-07-16T20:34:08.967

2

I solved this by unticking the option "enable ctrl key shortcuts" in the terminal options. find the setting by -> right click on terminal frame -> select properties.

Steve

Posted 2018-07-16T18:47:22.677

Reputation: 21

0

Note that Ctrl-A is not likely what bash's "bind" feature uses to move the cursor to the start of the line. Rather, bash responds to ASCII code one.

With many terminal programs, pressing Ctrl-A will result in sending ASCII code one to the foreground program. However, it seems your terminal program is using Ctrl-A to accomplish a different task. Therefore, when you press Ctrl-A, the terminal program does not send the ASCII code one to bash, and so bash never receives it. That's why bash isn't moving your cursor.

One solution, and quite possibly the very best solution, is likely in the terminal program's settings (which a comment, and another answer on this page, already address).

However, there is likely another easily available work-around. That is: Hold down the Alt key, and press the number one on the numpad. (If you are using a laptop, sometimes the numpad numbers are unavailable unless you also hold down a key labelled "Fn".) After pressing and releasing the num pad's number one, release the Alt key.

When you release the Alt key, the result is likely to send the specified ASCII code (ASCII code one) to the terminal program.

Yet another approach, although admittedly much more complicated, may be to somehow get ASCII code one into your clipboard, and then have your terminal program paste the contents of your clipboard (which can often be done by using Ctrl-V).

TOOGAM

Posted 2018-07-16T18:47:22.677

Reputation: 12 651