Can you interactively modify the terminal reset in 'less'?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I usually do not want to reset the terminal when I exit less (that is, I want the screen to continue displaying what I was looking at). Usually, when I'm on a new box and haven't configured it yet, I invoke less, quit, see the screen reset, curse mildly, and rerun with less -X ... On very rare occasions, I remember that the screen is going to reset as soon as I quit, in which case the sequence of events is slightly modified and the mild cursing occurs before I quit, but the overall effect is about the same.



Is there any way to modify a currently running less process so that it will not reset the terminal upon exit?










share|improve this question





















  • short - no. long - see my answer.
    – Thomas Dickey
    2 hours ago














up vote
1
down vote

favorite












I usually do not want to reset the terminal when I exit less (that is, I want the screen to continue displaying what I was looking at). Usually, when I'm on a new box and haven't configured it yet, I invoke less, quit, see the screen reset, curse mildly, and rerun with less -X ... On very rare occasions, I remember that the screen is going to reset as soon as I quit, in which case the sequence of events is slightly modified and the mild cursing occurs before I quit, but the overall effect is about the same.



Is there any way to modify a currently running less process so that it will not reset the terminal upon exit?










share|improve this question





















  • short - no. long - see my answer.
    – Thomas Dickey
    2 hours ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I usually do not want to reset the terminal when I exit less (that is, I want the screen to continue displaying what I was looking at). Usually, when I'm on a new box and haven't configured it yet, I invoke less, quit, see the screen reset, curse mildly, and rerun with less -X ... On very rare occasions, I remember that the screen is going to reset as soon as I quit, in which case the sequence of events is slightly modified and the mild cursing occurs before I quit, but the overall effect is about the same.



Is there any way to modify a currently running less process so that it will not reset the terminal upon exit?










share|improve this question













I usually do not want to reset the terminal when I exit less (that is, I want the screen to continue displaying what I was looking at). Usually, when I'm on a new box and haven't configured it yet, I invoke less, quit, see the screen reset, curse mildly, and rerun with less -X ... On very rare occasions, I remember that the screen is going to reset as soon as I quit, in which case the sequence of events is slightly modified and the mild cursing occurs before I quit, but the overall effect is about the same.



Is there any way to modify a currently running less process so that it will not reset the terminal upon exit?







less terminfo termcap






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 3 hours ago









William Pursell

2,12911112




2,12911112











  • short - no. long - see my answer.
    – Thomas Dickey
    2 hours ago
















  • short - no. long - see my answer.
    – Thomas Dickey
    2 hours ago















short - no. long - see my answer.
– Thomas Dickey
2 hours ago




short - no. long - see my answer.
– Thomas Dickey
2 hours ago










2 Answers
2






active

oldest

votes

















up vote
2
down vote













Some terminals (such as xterm) have a menu setting which enable/disables switching to/from alternate screen. Most do not...



By the way (same issue of some/most), if a terminal implements the original xterm 47 code alternate-screen switching, it is possible to switch back into the alternate screen without clearing it. I've noticed some which set TERM=xterm which do not implement this (only implementing the later 1049 code) - ymmv



You can see how the 47 code is used in a normal terminal description by looking at the smcup and rmcup capabilities from



infocmp xterm-old


which shows these items (among others):



rmcup=E[2JE[?47lE8,
smcup=E7E[?47h,


The E[2J in rmcup clears the (alternate) screen before switching back to the normal screen. The E7 and E8 save/restore the cursor position (for the normal screen). If you really wanted to, you could replace those capabilities with whatever xterm-compatible terminal description, omitting the clear-screen part, allowing you to do



tput smcup
tput rmcup


from the command-line and see what was on the alternate screen. It wouldn't be nice (since your command-line would overwrite parts of it), but it might help.



It's not needed in xterm, since xterm has a menu option for switching back/forth. But you might find that approach useful.



Further reading:




  • Why doesn't the screen clear when running vi? (xterm FAQ)

  • XTerm Control Sequences





share|improve this answer



























    up vote
    2
    down vote













    use | . cat.



    Stepwise: press |, then at the |mark: prompt press ., then at the ! prompt enter cat, then at the |done (press RETURN) prompt press Enter again; when you quit less, the current page we be left on the screen.



    If you want the output to be processed as it was by less (with backspace+underscore transformed to underline, non-printable characters shown as <XX>, etc), use less -FX instead of cat.



    from the less(1) manpage:




     | <m> shell-command
    <m> represents any mark letter. Pipes a section of the input
    file to the given shell command. The section of the file to be
    piped is between the first line on the current screen and the
    position marked by the letter. <m> may also be ^ or $ to indi-
    cate beginning or end of file respectively. If <m> is . or new-
    line, the current screen is piped.



    Afterwards, if you want to simply zap the rmcup/smcup alternate screen switching without having to reconfigure again and again every xterm clone, you can use this command:



    infocmp | sed 's/[sr]mcup=[^=]*,//g' | tic -


    This will write inside ~/.terminfo a terminal description for your current terminal with the codes for alternate screen switching omitted. It should be used in preference to that from /usr/share/terminfo by most programs.






    share|improve this answer






















    • That prints the file which less is rendering, but it's not the same, e.g., if it contains non-printing characters (and does not affect the reset).
      – Thomas Dickey
      2 hours ago










    • @ThomasDickey I hope I addressed your objections in the last revision.
      – qubert
      2 hours ago










    • That's better (writing an approximation to the normal screen), though as noted, you can't modify the reset from within less :-)
      – Thomas Dickey
      2 hours ago










    • This is ingenious. To make sure I understand what's happening, less writes to the alternate screen and the shell out to cat writes to the normal screen?
      – William Pursell
      1 hour ago










    • @WilliamPursell exactly.
      – qubert
      1 hour ago










    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%2f477854%2fcan-you-interactively-modify-the-terminal-reset-in-less%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
    2
    down vote













    Some terminals (such as xterm) have a menu setting which enable/disables switching to/from alternate screen. Most do not...



    By the way (same issue of some/most), if a terminal implements the original xterm 47 code alternate-screen switching, it is possible to switch back into the alternate screen without clearing it. I've noticed some which set TERM=xterm which do not implement this (only implementing the later 1049 code) - ymmv



    You can see how the 47 code is used in a normal terminal description by looking at the smcup and rmcup capabilities from



    infocmp xterm-old


    which shows these items (among others):



    rmcup=E[2JE[?47lE8,
    smcup=E7E[?47h,


    The E[2J in rmcup clears the (alternate) screen before switching back to the normal screen. The E7 and E8 save/restore the cursor position (for the normal screen). If you really wanted to, you could replace those capabilities with whatever xterm-compatible terminal description, omitting the clear-screen part, allowing you to do



    tput smcup
    tput rmcup


    from the command-line and see what was on the alternate screen. It wouldn't be nice (since your command-line would overwrite parts of it), but it might help.



    It's not needed in xterm, since xterm has a menu option for switching back/forth. But you might find that approach useful.



    Further reading:




    • Why doesn't the screen clear when running vi? (xterm FAQ)

    • XTerm Control Sequences





    share|improve this answer
























      up vote
      2
      down vote













      Some terminals (such as xterm) have a menu setting which enable/disables switching to/from alternate screen. Most do not...



      By the way (same issue of some/most), if a terminal implements the original xterm 47 code alternate-screen switching, it is possible to switch back into the alternate screen without clearing it. I've noticed some which set TERM=xterm which do not implement this (only implementing the later 1049 code) - ymmv



      You can see how the 47 code is used in a normal terminal description by looking at the smcup and rmcup capabilities from



      infocmp xterm-old


      which shows these items (among others):



      rmcup=E[2JE[?47lE8,
      smcup=E7E[?47h,


      The E[2J in rmcup clears the (alternate) screen before switching back to the normal screen. The E7 and E8 save/restore the cursor position (for the normal screen). If you really wanted to, you could replace those capabilities with whatever xterm-compatible terminal description, omitting the clear-screen part, allowing you to do



      tput smcup
      tput rmcup


      from the command-line and see what was on the alternate screen. It wouldn't be nice (since your command-line would overwrite parts of it), but it might help.



      It's not needed in xterm, since xterm has a menu option for switching back/forth. But you might find that approach useful.



      Further reading:




      • Why doesn't the screen clear when running vi? (xterm FAQ)

      • XTerm Control Sequences





      share|improve this answer






















        up vote
        2
        down vote










        up vote
        2
        down vote









        Some terminals (such as xterm) have a menu setting which enable/disables switching to/from alternate screen. Most do not...



        By the way (same issue of some/most), if a terminal implements the original xterm 47 code alternate-screen switching, it is possible to switch back into the alternate screen without clearing it. I've noticed some which set TERM=xterm which do not implement this (only implementing the later 1049 code) - ymmv



        You can see how the 47 code is used in a normal terminal description by looking at the smcup and rmcup capabilities from



        infocmp xterm-old


        which shows these items (among others):



        rmcup=E[2JE[?47lE8,
        smcup=E7E[?47h,


        The E[2J in rmcup clears the (alternate) screen before switching back to the normal screen. The E7 and E8 save/restore the cursor position (for the normal screen). If you really wanted to, you could replace those capabilities with whatever xterm-compatible terminal description, omitting the clear-screen part, allowing you to do



        tput smcup
        tput rmcup


        from the command-line and see what was on the alternate screen. It wouldn't be nice (since your command-line would overwrite parts of it), but it might help.



        It's not needed in xterm, since xterm has a menu option for switching back/forth. But you might find that approach useful.



        Further reading:




        • Why doesn't the screen clear when running vi? (xterm FAQ)

        • XTerm Control Sequences





        share|improve this answer












        Some terminals (such as xterm) have a menu setting which enable/disables switching to/from alternate screen. Most do not...



        By the way (same issue of some/most), if a terminal implements the original xterm 47 code alternate-screen switching, it is possible to switch back into the alternate screen without clearing it. I've noticed some which set TERM=xterm which do not implement this (only implementing the later 1049 code) - ymmv



        You can see how the 47 code is used in a normal terminal description by looking at the smcup and rmcup capabilities from



        infocmp xterm-old


        which shows these items (among others):



        rmcup=E[2JE[?47lE8,
        smcup=E7E[?47h,


        The E[2J in rmcup clears the (alternate) screen before switching back to the normal screen. The E7 and E8 save/restore the cursor position (for the normal screen). If you really wanted to, you could replace those capabilities with whatever xterm-compatible terminal description, omitting the clear-screen part, allowing you to do



        tput smcup
        tput rmcup


        from the command-line and see what was on the alternate screen. It wouldn't be nice (since your command-line would overwrite parts of it), but it might help.



        It's not needed in xterm, since xterm has a menu option for switching back/forth. But you might find that approach useful.



        Further reading:




        • Why doesn't the screen clear when running vi? (xterm FAQ)

        • XTerm Control Sequences






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 hours ago









        Thomas Dickey

        51.1k593162




        51.1k593162






















            up vote
            2
            down vote













            use | . cat.



            Stepwise: press |, then at the |mark: prompt press ., then at the ! prompt enter cat, then at the |done (press RETURN) prompt press Enter again; when you quit less, the current page we be left on the screen.



            If you want the output to be processed as it was by less (with backspace+underscore transformed to underline, non-printable characters shown as <XX>, etc), use less -FX instead of cat.



            from the less(1) manpage:




             | <m> shell-command
            <m> represents any mark letter. Pipes a section of the input
            file to the given shell command. The section of the file to be
            piped is between the first line on the current screen and the
            position marked by the letter. <m> may also be ^ or $ to indi-
            cate beginning or end of file respectively. If <m> is . or new-
            line, the current screen is piped.



            Afterwards, if you want to simply zap the rmcup/smcup alternate screen switching without having to reconfigure again and again every xterm clone, you can use this command:



            infocmp | sed 's/[sr]mcup=[^=]*,//g' | tic -


            This will write inside ~/.terminfo a terminal description for your current terminal with the codes for alternate screen switching omitted. It should be used in preference to that from /usr/share/terminfo by most programs.






            share|improve this answer






















            • That prints the file which less is rendering, but it's not the same, e.g., if it contains non-printing characters (and does not affect the reset).
              – Thomas Dickey
              2 hours ago










            • @ThomasDickey I hope I addressed your objections in the last revision.
              – qubert
              2 hours ago










            • That's better (writing an approximation to the normal screen), though as noted, you can't modify the reset from within less :-)
              – Thomas Dickey
              2 hours ago










            • This is ingenious. To make sure I understand what's happening, less writes to the alternate screen and the shell out to cat writes to the normal screen?
              – William Pursell
              1 hour ago










            • @WilliamPursell exactly.
              – qubert
              1 hour ago














            up vote
            2
            down vote













            use | . cat.



            Stepwise: press |, then at the |mark: prompt press ., then at the ! prompt enter cat, then at the |done (press RETURN) prompt press Enter again; when you quit less, the current page we be left on the screen.



            If you want the output to be processed as it was by less (with backspace+underscore transformed to underline, non-printable characters shown as <XX>, etc), use less -FX instead of cat.



            from the less(1) manpage:




             | <m> shell-command
            <m> represents any mark letter. Pipes a section of the input
            file to the given shell command. The section of the file to be
            piped is between the first line on the current screen and the
            position marked by the letter. <m> may also be ^ or $ to indi-
            cate beginning or end of file respectively. If <m> is . or new-
            line, the current screen is piped.



            Afterwards, if you want to simply zap the rmcup/smcup alternate screen switching without having to reconfigure again and again every xterm clone, you can use this command:



            infocmp | sed 's/[sr]mcup=[^=]*,//g' | tic -


            This will write inside ~/.terminfo a terminal description for your current terminal with the codes for alternate screen switching omitted. It should be used in preference to that from /usr/share/terminfo by most programs.






            share|improve this answer






















            • That prints the file which less is rendering, but it's not the same, e.g., if it contains non-printing characters (and does not affect the reset).
              – Thomas Dickey
              2 hours ago










            • @ThomasDickey I hope I addressed your objections in the last revision.
              – qubert
              2 hours ago










            • That's better (writing an approximation to the normal screen), though as noted, you can't modify the reset from within less :-)
              – Thomas Dickey
              2 hours ago










            • This is ingenious. To make sure I understand what's happening, less writes to the alternate screen and the shell out to cat writes to the normal screen?
              – William Pursell
              1 hour ago










            • @WilliamPursell exactly.
              – qubert
              1 hour ago












            up vote
            2
            down vote










            up vote
            2
            down vote









            use | . cat.



            Stepwise: press |, then at the |mark: prompt press ., then at the ! prompt enter cat, then at the |done (press RETURN) prompt press Enter again; when you quit less, the current page we be left on the screen.



            If you want the output to be processed as it was by less (with backspace+underscore transformed to underline, non-printable characters shown as <XX>, etc), use less -FX instead of cat.



            from the less(1) manpage:




             | <m> shell-command
            <m> represents any mark letter. Pipes a section of the input
            file to the given shell command. The section of the file to be
            piped is between the first line on the current screen and the
            position marked by the letter. <m> may also be ^ or $ to indi-
            cate beginning or end of file respectively. If <m> is . or new-
            line, the current screen is piped.



            Afterwards, if you want to simply zap the rmcup/smcup alternate screen switching without having to reconfigure again and again every xterm clone, you can use this command:



            infocmp | sed 's/[sr]mcup=[^=]*,//g' | tic -


            This will write inside ~/.terminfo a terminal description for your current terminal with the codes for alternate screen switching omitted. It should be used in preference to that from /usr/share/terminfo by most programs.






            share|improve this answer














            use | . cat.



            Stepwise: press |, then at the |mark: prompt press ., then at the ! prompt enter cat, then at the |done (press RETURN) prompt press Enter again; when you quit less, the current page we be left on the screen.



            If you want the output to be processed as it was by less (with backspace+underscore transformed to underline, non-printable characters shown as <XX>, etc), use less -FX instead of cat.



            from the less(1) manpage:




             | <m> shell-command
            <m> represents any mark letter. Pipes a section of the input
            file to the given shell command. The section of the file to be
            piped is between the first line on the current screen and the
            position marked by the letter. <m> may also be ^ or $ to indi-
            cate beginning or end of file respectively. If <m> is . or new-
            line, the current screen is piped.



            Afterwards, if you want to simply zap the rmcup/smcup alternate screen switching without having to reconfigure again and again every xterm clone, you can use this command:



            infocmp | sed 's/[sr]mcup=[^=]*,//g' | tic -


            This will write inside ~/.terminfo a terminal description for your current terminal with the codes for alternate screen switching omitted. It should be used in preference to that from /usr/share/terminfo by most programs.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 13 mins ago









            Jeff Schaller

            34.5k951115




            34.5k951115










            answered 2 hours ago









            qubert

            1934




            1934











            • That prints the file which less is rendering, but it's not the same, e.g., if it contains non-printing characters (and does not affect the reset).
              – Thomas Dickey
              2 hours ago










            • @ThomasDickey I hope I addressed your objections in the last revision.
              – qubert
              2 hours ago










            • That's better (writing an approximation to the normal screen), though as noted, you can't modify the reset from within less :-)
              – Thomas Dickey
              2 hours ago










            • This is ingenious. To make sure I understand what's happening, less writes to the alternate screen and the shell out to cat writes to the normal screen?
              – William Pursell
              1 hour ago










            • @WilliamPursell exactly.
              – qubert
              1 hour ago
















            • That prints the file which less is rendering, but it's not the same, e.g., if it contains non-printing characters (and does not affect the reset).
              – Thomas Dickey
              2 hours ago










            • @ThomasDickey I hope I addressed your objections in the last revision.
              – qubert
              2 hours ago










            • That's better (writing an approximation to the normal screen), though as noted, you can't modify the reset from within less :-)
              – Thomas Dickey
              2 hours ago










            • This is ingenious. To make sure I understand what's happening, less writes to the alternate screen and the shell out to cat writes to the normal screen?
              – William Pursell
              1 hour ago










            • @WilliamPursell exactly.
              – qubert
              1 hour ago















            That prints the file which less is rendering, but it's not the same, e.g., if it contains non-printing characters (and does not affect the reset).
            – Thomas Dickey
            2 hours ago




            That prints the file which less is rendering, but it's not the same, e.g., if it contains non-printing characters (and does not affect the reset).
            – Thomas Dickey
            2 hours ago












            @ThomasDickey I hope I addressed your objections in the last revision.
            – qubert
            2 hours ago




            @ThomasDickey I hope I addressed your objections in the last revision.
            – qubert
            2 hours ago












            That's better (writing an approximation to the normal screen), though as noted, you can't modify the reset from within less :-)
            – Thomas Dickey
            2 hours ago




            That's better (writing an approximation to the normal screen), though as noted, you can't modify the reset from within less :-)
            – Thomas Dickey
            2 hours ago












            This is ingenious. To make sure I understand what's happening, less writes to the alternate screen and the shell out to cat writes to the normal screen?
            – William Pursell
            1 hour ago




            This is ingenious. To make sure I understand what's happening, less writes to the alternate screen and the shell out to cat writes to the normal screen?
            – William Pursell
            1 hour ago












            @WilliamPursell exactly.
            – qubert
            1 hour ago




            @WilliamPursell exactly.
            – qubert
            1 hour ago

















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f477854%2fcan-you-interactively-modify-the-terminal-reset-in-less%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery