Nano editor: are Ctrl keybindings actually bitmasked?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I wanted to make Nano have more common shortcuts (i.e. Ctrl-F for search, Ctrl-H for replace, etc) and edited the nanorc
file to add:
bind ^F whereis all
bind ^H replace all
bind ^M mark all
...
To my astonishment, pressing Backspace activates the Replace function and pressing Enter activates Mark.
Then i realized their virtual keycodes are: Backspace 0x08, H 0x48, Enter 0x0D, M 0x4D.
Are the Ctrl keybindings actually bitmasked on 0x40?
nano
migrated from serverfault.com Sep 28 at 9:53
This question came from our site for system and network administrators.
add a comment |Â
up vote
1
down vote
favorite
I wanted to make Nano have more common shortcuts (i.e. Ctrl-F for search, Ctrl-H for replace, etc) and edited the nanorc
file to add:
bind ^F whereis all
bind ^H replace all
bind ^M mark all
...
To my astonishment, pressing Backspace activates the Replace function and pressing Enter activates Mark.
Then i realized their virtual keycodes are: Backspace 0x08, H 0x48, Enter 0x0D, M 0x4D.
Are the Ctrl keybindings actually bitmasked on 0x40?
nano
migrated from serverfault.com Sep 28 at 9:53
This question came from our site for system and network administrators.
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I wanted to make Nano have more common shortcuts (i.e. Ctrl-F for search, Ctrl-H for replace, etc) and edited the nanorc
file to add:
bind ^F whereis all
bind ^H replace all
bind ^M mark all
...
To my astonishment, pressing Backspace activates the Replace function and pressing Enter activates Mark.
Then i realized their virtual keycodes are: Backspace 0x08, H 0x48, Enter 0x0D, M 0x4D.
Are the Ctrl keybindings actually bitmasked on 0x40?
nano
I wanted to make Nano have more common shortcuts (i.e. Ctrl-F for search, Ctrl-H for replace, etc) and edited the nanorc
file to add:
bind ^F whereis all
bind ^H replace all
bind ^M mark all
...
To my astonishment, pressing Backspace activates the Replace function and pressing Enter activates Mark.
Then i realized their virtual keycodes are: Backspace 0x08, H 0x48, Enter 0x0D, M 0x4D.
Are the Ctrl keybindings actually bitmasked on 0x40?
nano
nano
asked Sep 28 at 9:46
iamanigeeit
1062
1062
migrated from serverfault.com Sep 28 at 9:53
This question came from our site for system and network administrators.
migrated from serverfault.com Sep 28 at 9:53
This question came from our site for system and network administrators.
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
The virtual terminal you are using nano on is modelled after the physical serial terminals of past decades. By convention, these terminals produced ASCII control codes when a letter key or one of the keys labelled @
, [
, ,
]
, ^
, _
were pressed together with the Ctrl
key. The control code emitted has the ASCII code of the code of the letter subtracted by 64. Thus pressing Ctrl-M
produces the ASCII code of M (0x53) subtracted by 0x40 = 0x13, which is the code for Carriage Return. The Return key also produces Carriage Return, because that's the function of the the key.
add a comment |Â
up vote
1
down vote
These are not virtual keycodes.
You are using a terminal.
Terminals operate with a simple 8-bit, sometimes even 7-bit, character stream. For all that a TUI application like nano
knows, there are a serial port, two modems, the PSTN, and an honest-to-goodness DEC VT525 between you and it. All that it sees is that character stream, a terminal device file descriptor, a TERM
environment variable, and record in the terminfo database.
There's no such thing as a control key modifier for an alphabetic key in that character stream. When you write bind ^M
the software is actually understanding that as binding character number 13. That's how the software has to work internally, because that is the actual terminal I/O model that it has to work with. The ^M
is an artefact of the software's command parser, a way to denote character number 13 in configuration commands that you type.
Some operating systems, like FreeBSD, provide common library functions that applications softwares can use in their parsers, to yield uniform semantics for such denotations across applications.
% printf 'x08x0d' | vis -w ; echo
^H^M
%
There are no virtual key codes here, moreover. All of the translation caused by the â Control modifier key happens in your terminal or terminal emulator, before the characters are transmitted down the (virtual or actual) wire.
It just so happens that your terminal produces character #8 (â) for â Control+H and â«Â Backspace and character 13 (â) for â Control+M and Enter. This is entirely up to the terminal/terminal emulator. With many emulators there is a keyboard map of some sort where one can change this. For bona fide DEC VTs, there is in fact an output control sequence, DECBKM, that switches â«Â Backspace between sending character #8 and sending character #127 (DEL).
Further reading
- https://unix.stackexchange.com/a/382814/5132
- Why doesn't the Enter key send EOL?
- Display tab characters as `^I`
vis()
,strvis()
, et al.. FreeBSD Library Functions Manual. 2017-04-22.unvis
. FreeBSD General Commands Manual. 2010-11-07.
Thanks for the explanation. So let's say i change my terminal to add 128 to the character code when i press Ctrl. How do i configure Nano to accept bytes 128-255?
â iamanigeeit
Oct 1 at 9:55
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
The virtual terminal you are using nano on is modelled after the physical serial terminals of past decades. By convention, these terminals produced ASCII control codes when a letter key or one of the keys labelled @
, [
, ,
]
, ^
, _
were pressed together with the Ctrl
key. The control code emitted has the ASCII code of the code of the letter subtracted by 64. Thus pressing Ctrl-M
produces the ASCII code of M (0x53) subtracted by 0x40 = 0x13, which is the code for Carriage Return. The Return key also produces Carriage Return, because that's the function of the the key.
add a comment |Â
up vote
1
down vote
The virtual terminal you are using nano on is modelled after the physical serial terminals of past decades. By convention, these terminals produced ASCII control codes when a letter key or one of the keys labelled @
, [
, ,
]
, ^
, _
were pressed together with the Ctrl
key. The control code emitted has the ASCII code of the code of the letter subtracted by 64. Thus pressing Ctrl-M
produces the ASCII code of M (0x53) subtracted by 0x40 = 0x13, which is the code for Carriage Return. The Return key also produces Carriage Return, because that's the function of the the key.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
The virtual terminal you are using nano on is modelled after the physical serial terminals of past decades. By convention, these terminals produced ASCII control codes when a letter key or one of the keys labelled @
, [
, ,
]
, ^
, _
were pressed together with the Ctrl
key. The control code emitted has the ASCII code of the code of the letter subtracted by 64. Thus pressing Ctrl-M
produces the ASCII code of M (0x53) subtracted by 0x40 = 0x13, which is the code for Carriage Return. The Return key also produces Carriage Return, because that's the function of the the key.
The virtual terminal you are using nano on is modelled after the physical serial terminals of past decades. By convention, these terminals produced ASCII control codes when a letter key or one of the keys labelled @
, [
, ,
]
, ^
, _
were pressed together with the Ctrl
key. The control code emitted has the ASCII code of the code of the letter subtracted by 64. Thus pressing Ctrl-M
produces the ASCII code of M (0x53) subtracted by 0x40 = 0x13, which is the code for Carriage Return. The Return key also produces Carriage Return, because that's the function of the the key.
answered Sep 28 at 11:41
Johan Myréen
7,02611423
7,02611423
add a comment |Â
add a comment |Â
up vote
1
down vote
These are not virtual keycodes.
You are using a terminal.
Terminals operate with a simple 8-bit, sometimes even 7-bit, character stream. For all that a TUI application like nano
knows, there are a serial port, two modems, the PSTN, and an honest-to-goodness DEC VT525 between you and it. All that it sees is that character stream, a terminal device file descriptor, a TERM
environment variable, and record in the terminfo database.
There's no such thing as a control key modifier for an alphabetic key in that character stream. When you write bind ^M
the software is actually understanding that as binding character number 13. That's how the software has to work internally, because that is the actual terminal I/O model that it has to work with. The ^M
is an artefact of the software's command parser, a way to denote character number 13 in configuration commands that you type.
Some operating systems, like FreeBSD, provide common library functions that applications softwares can use in their parsers, to yield uniform semantics for such denotations across applications.
% printf 'x08x0d' | vis -w ; echo
^H^M
%
There are no virtual key codes here, moreover. All of the translation caused by the â Control modifier key happens in your terminal or terminal emulator, before the characters are transmitted down the (virtual or actual) wire.
It just so happens that your terminal produces character #8 (â) for â Control+H and â«Â Backspace and character 13 (â) for â Control+M and Enter. This is entirely up to the terminal/terminal emulator. With many emulators there is a keyboard map of some sort where one can change this. For bona fide DEC VTs, there is in fact an output control sequence, DECBKM, that switches â«Â Backspace between sending character #8 and sending character #127 (DEL).
Further reading
- https://unix.stackexchange.com/a/382814/5132
- Why doesn't the Enter key send EOL?
- Display tab characters as `^I`
vis()
,strvis()
, et al.. FreeBSD Library Functions Manual. 2017-04-22.unvis
. FreeBSD General Commands Manual. 2010-11-07.
Thanks for the explanation. So let's say i change my terminal to add 128 to the character code when i press Ctrl. How do i configure Nano to accept bytes 128-255?
â iamanigeeit
Oct 1 at 9:55
add a comment |Â
up vote
1
down vote
These are not virtual keycodes.
You are using a terminal.
Terminals operate with a simple 8-bit, sometimes even 7-bit, character stream. For all that a TUI application like nano
knows, there are a serial port, two modems, the PSTN, and an honest-to-goodness DEC VT525 between you and it. All that it sees is that character stream, a terminal device file descriptor, a TERM
environment variable, and record in the terminfo database.
There's no such thing as a control key modifier for an alphabetic key in that character stream. When you write bind ^M
the software is actually understanding that as binding character number 13. That's how the software has to work internally, because that is the actual terminal I/O model that it has to work with. The ^M
is an artefact of the software's command parser, a way to denote character number 13 in configuration commands that you type.
Some operating systems, like FreeBSD, provide common library functions that applications softwares can use in their parsers, to yield uniform semantics for such denotations across applications.
% printf 'x08x0d' | vis -w ; echo
^H^M
%
There are no virtual key codes here, moreover. All of the translation caused by the â Control modifier key happens in your terminal or terminal emulator, before the characters are transmitted down the (virtual or actual) wire.
It just so happens that your terminal produces character #8 (â) for â Control+H and â«Â Backspace and character 13 (â) for â Control+M and Enter. This is entirely up to the terminal/terminal emulator. With many emulators there is a keyboard map of some sort where one can change this. For bona fide DEC VTs, there is in fact an output control sequence, DECBKM, that switches â«Â Backspace between sending character #8 and sending character #127 (DEL).
Further reading
- https://unix.stackexchange.com/a/382814/5132
- Why doesn't the Enter key send EOL?
- Display tab characters as `^I`
vis()
,strvis()
, et al.. FreeBSD Library Functions Manual. 2017-04-22.unvis
. FreeBSD General Commands Manual. 2010-11-07.
Thanks for the explanation. So let's say i change my terminal to add 128 to the character code when i press Ctrl. How do i configure Nano to accept bytes 128-255?
â iamanigeeit
Oct 1 at 9:55
add a comment |Â
up vote
1
down vote
up vote
1
down vote
These are not virtual keycodes.
You are using a terminal.
Terminals operate with a simple 8-bit, sometimes even 7-bit, character stream. For all that a TUI application like nano
knows, there are a serial port, two modems, the PSTN, and an honest-to-goodness DEC VT525 between you and it. All that it sees is that character stream, a terminal device file descriptor, a TERM
environment variable, and record in the terminfo database.
There's no such thing as a control key modifier for an alphabetic key in that character stream. When you write bind ^M
the software is actually understanding that as binding character number 13. That's how the software has to work internally, because that is the actual terminal I/O model that it has to work with. The ^M
is an artefact of the software's command parser, a way to denote character number 13 in configuration commands that you type.
Some operating systems, like FreeBSD, provide common library functions that applications softwares can use in their parsers, to yield uniform semantics for such denotations across applications.
% printf 'x08x0d' | vis -w ; echo
^H^M
%
There are no virtual key codes here, moreover. All of the translation caused by the â Control modifier key happens in your terminal or terminal emulator, before the characters are transmitted down the (virtual or actual) wire.
It just so happens that your terminal produces character #8 (â) for â Control+H and â«Â Backspace and character 13 (â) for â Control+M and Enter. This is entirely up to the terminal/terminal emulator. With many emulators there is a keyboard map of some sort where one can change this. For bona fide DEC VTs, there is in fact an output control sequence, DECBKM, that switches â«Â Backspace between sending character #8 and sending character #127 (DEL).
Further reading
- https://unix.stackexchange.com/a/382814/5132
- Why doesn't the Enter key send EOL?
- Display tab characters as `^I`
vis()
,strvis()
, et al.. FreeBSD Library Functions Manual. 2017-04-22.unvis
. FreeBSD General Commands Manual. 2010-11-07.
These are not virtual keycodes.
You are using a terminal.
Terminals operate with a simple 8-bit, sometimes even 7-bit, character stream. For all that a TUI application like nano
knows, there are a serial port, two modems, the PSTN, and an honest-to-goodness DEC VT525 between you and it. All that it sees is that character stream, a terminal device file descriptor, a TERM
environment variable, and record in the terminfo database.
There's no such thing as a control key modifier for an alphabetic key in that character stream. When you write bind ^M
the software is actually understanding that as binding character number 13. That's how the software has to work internally, because that is the actual terminal I/O model that it has to work with. The ^M
is an artefact of the software's command parser, a way to denote character number 13 in configuration commands that you type.
Some operating systems, like FreeBSD, provide common library functions that applications softwares can use in their parsers, to yield uniform semantics for such denotations across applications.
% printf 'x08x0d' | vis -w ; echo
^H^M
%
There are no virtual key codes here, moreover. All of the translation caused by the â Control modifier key happens in your terminal or terminal emulator, before the characters are transmitted down the (virtual or actual) wire.
It just so happens that your terminal produces character #8 (â) for â Control+H and â«Â Backspace and character 13 (â) for â Control+M and Enter. This is entirely up to the terminal/terminal emulator. With many emulators there is a keyboard map of some sort where one can change this. For bona fide DEC VTs, there is in fact an output control sequence, DECBKM, that switches â«Â Backspace between sending character #8 and sending character #127 (DEL).
Further reading
- https://unix.stackexchange.com/a/382814/5132
- Why doesn't the Enter key send EOL?
- Display tab characters as `^I`
vis()
,strvis()
, et al.. FreeBSD Library Functions Manual. 2017-04-22.unvis
. FreeBSD General Commands Manual. 2010-11-07.
edited Sep 28 at 11:58
answered Sep 28 at 11:52
JdeBP
30k462137
30k462137
Thanks for the explanation. So let's say i change my terminal to add 128 to the character code when i press Ctrl. How do i configure Nano to accept bytes 128-255?
â iamanigeeit
Oct 1 at 9:55
add a comment |Â
Thanks for the explanation. So let's say i change my terminal to add 128 to the character code when i press Ctrl. How do i configure Nano to accept bytes 128-255?
â iamanigeeit
Oct 1 at 9:55
Thanks for the explanation. So let's say i change my terminal to add 128 to the character code when i press Ctrl. How do i configure Nano to accept bytes 128-255?
â iamanigeeit
Oct 1 at 9:55
Thanks for the explanation. So let's say i change my terminal to add 128 to the character code when i press Ctrl. How do i configure Nano to accept bytes 128-255?
â iamanigeeit
Oct 1 at 9:55
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472024%2fnano-editor-are-ctrl-keybindings-actually-bitmasked%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password