Nano editor: are Ctrl keybindings actually bitmasked?

The name of the pictureThe name of the pictureThe name of the pictureClash 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?










share|improve this question













migrated from serverfault.com Sep 28 at 9:53


This question came from our site for system and network administrators.


















    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?










    share|improve this question













    migrated from serverfault.com Sep 28 at 9:53


    This question came from our site for system and network administrators.
















      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?










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      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.






















          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.






          share|improve this answer



























            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.





            share|improve this answer






















            • 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











            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            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






























            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.






            share|improve this answer
























              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.






              share|improve this answer






















                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.






                share|improve this answer












                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Sep 28 at 11:41









                Johan Myréen

                7,02611423




                7,02611423






















                    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.





                    share|improve this answer






















                    • 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















                    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.





                    share|improve this answer






















                    • 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













                    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.





                    share|improve this answer














                    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.






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    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

















                    • 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


















                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    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













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay