Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I read in another post that you can type CtrlJ or CtrlM instead of the Return key in the terminal, which is great. But what I want to be able to do, is change that to another combination, for example: Ctrlspacebar. I've tried remapping the F1 key, to no avail.

Is this possible?

share|improve this question
add comment

1 Answer

Depends what exactly you want to do.

terminals have two major modes both of which can be fine tuned with extra settings:

  1. cooked/canonical mode. In that mode, the terminal comes with an internal line editor where the ^H (or ^?), ^W, ^U (or @), ^V (or \) characters can be used to edit the line. Nothing is sent to the application reading from the terminal device until the ^J character is received.
  2. raw mode. Where every character is available for reading to the application reading the terminal device as soon as it is typed, or after a delay or after so many have been entered depending on the time and min parameters, but in anycase, not with that internal line editor.

In both cases, the ^M (CR) character can be automatically translated to ^J (LF) (or ignored for those terminals that send both CR and LF upon pressing Enter).

The first mode is the default mode of the terminal. The second mode is used by applications like zsh, bash or vi that want to take control of the line editing.

In the first mode, you cannot change what character is used to accept the line.

But you may be able to tell your terminal to send the ^J character upon pressing this or that key. For instance, with xterm, you can use the translations X11 resource to change the key mapping and tell it to send whatever you want upon a given key press. If your terminal doesn't support remapping the keyboard, you can still use GNU screen to do the translation for you. For instance, if your terminal sends the ^[OP character sequence upon pressing F1, you can add

bindkey \033OP "\012"

to your ~/screenrc to tell it to send LF when you press F1

For the second case, that is where applications take control of the input, you can still use the same approach as above, but you could also configure each individual application to do this and that when you press F1

For instance, with zsh, the LF character is bound to the accept-line zsh widget. You could do:

bindkey "^[OA" accept-line

to have F1 bind to that same widget.

Note that Ctrl+Space usually sends the NUL character which you can refer to as \0 or ^@.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.