Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6661725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:18:51+00:00 2026-05-26T02:18:51+00:00

Is there a builtin command to clear shell while using shell in emacs? If

  • 0

Is there a builtin command to clear shell while using shell in emacs?

If not, is there an elisp function to achieve the same?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:18:51+00:00Added an answer on May 26, 2026 at 2:18 am

    Update February 2015

    Just noticed that Emacs now (version 25+) has the command comint-clear-buffer, bound to C-c M-o by default, that does what we need here, and probably is preferable to the answers I originally posted below.

    Options to consider:

    1. C-l will recenter the buffer. Pressing it repeatedly cycles the buffer, so that point appears at the top, middle, or bottom of the buffer. When it stops at the top, the buffer looks like it’s been cleared, although all the text is still there, out of view.

    2. C-x h marks the whole buffer, after which C-w kills it. This kills the last prompt as well, but after you enter the next command you get your prompt back.

    3. You can also use erase-buffer, which isn’t bound to a key by default, but it’s easily done (you can also use M-x erase-buffer:

        (defun my-shell-hook ()
          (local-set-key "\C-cl" 'erase-buffer))
    
        (add-hook 'shell-mode-hook 'my-shell-hook)
    

    That binds it to C-c l; you can pick what you like.

    1. A quick fix to re-create your prompt after clearing is possible:
        (defun my-clear ()
          (interactive)
          (erase-buffer)
          (comint-send-input))
    
        (defun my-shell-hook ()
          (local-set-key "\C-cl" 'my-clear))
    
        (add-hook 'shell-mode-hook 'my-shell-hook)
    

    After you’ve been using emacs for a while, marking and killing regions becomes natural, so you might find the first option is enough. If not, the last option is closest to what you want.

    EDIT: just found this on the emacs wiki, it’s better than my option 4:

    (defun my-clear ()
      (interactive)
      (let ((comint-buffer-maximum-size 0))
        (comint-truncate-buffer)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any Ruby equivalent for Python's builtin zip function? If not, what is
Is there a builtin function in PHP to intelligently join path strings? The function,
Does anyone know if there is a builtin function for reading from the console
Using R's builtin ToothGrowth example dataset, this works: ddply(ToothGrowth, .(supp,dose), function(df) mean(df$len)) But I
NOTE: This is not the same question as Python: Persistent shell variables in subprocess
Is there a built-in or 3rd party elisp command to move to the matching
Is there a built-in method in Python to execute a system command without displaying
Is there builtin method that would do this or do I always have to
There are no builtin matrix functions in C#, but there are in the F#
Is there any way to Use the Builtin ScrollBars that comes with each .Net

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.