49

How to clear console in sublime text editor. I have searched on internet too..But can't find proper shortcut for that. Please provide info

dreftymac
  • 31,404
  • 26
  • 119
  • 182
Curious_k.shree
  • 990
  • 2
  • 18
  • 37
  • 3
    As omissions go, this one is pretty huge. Actually, I don't know of any piece of software that has a console window that doesn't have an immediate button or shortcut to clear it. It's vital. – Henrik Erlandsson Apr 25 '18 at 13:30

3 Answers3

93

I assume you're talking about the console accessible via View -> Show Console or Ctrl`. Unlike other answers on SO, which deal with clearing the Python console when opened from the command prompt, os.system("cls") or os.system("clear") (depending on your OS) don't work with the Sublime console. The Sublime API (version 2 or version 3) does not have any built-in console-clearing method, and I was unable to find any undocumented method in sublime.py or sublime_plugin.py. The console appears to be read-only, as selecting all the text and hitting Delete doesn't work either.

I've been looking into this for some time, and I've come to the conclusion that it does not appear to be possible. However, there is a hackish workaround - just run print('\n'*100) to print 100 newline characters, and you won't be able to see any of the previous output unless you scroll up some distance.

Community
  • 1
  • 1
MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • 16
    @MattDMo Wow. So creativity. Such great. Very thanks. – pilau Nov 11 '14 at 13:32
  • 9
    Thanks for this, I put it into a [plugin](https://github.com/saadq/ClearConsole) so if you install `ClearConsole` through Package Control, you can just type `alt+k` to clear the console using this method. – Saad May 29 '16 at 01:48
  • @saadq that's great, but could you please reference me as well as this question in your code? You should *always* reference code you take from other sources. You can [link to me on Github](https://github.com/MattDMo) or my Stack Overflow [user profile](http://stackoverflow.com/users/1426065/mattdmo). The specific URL for this answer is `http://stackoverflow.com/a/24760927`. – MattDMo May 29 '16 at 20:28
  • Hey @MattDMo I did already have this question referenced in the README, but I'll link to your GitHub as well. Sorry about that, didn't mean to take away any credit from you. – Saad May 30 '16 at 01:10
  • @saadq no prob, thanks! I think I just glanced over the README before, and nothing immediately jumped out at me, so it may have been my poor reading skills as well :) Anyways, thanks for the shoutout! – MattDMo May 30 '16 at 01:50
  • @saadq I suggest you move to the beginning or the end of the contents of the console after running that command on the plugin. otherwise when you check your errors you generally never stay on the bottom. then run Alt+K again, and you have to scrolldown again and again... :-) – Darkgaze Sep 27 '17 at 13:35
18

I installed ClearConsole package, then type alt+k to clear then console.

yujiezhang
  • 189
  • 1
  • 3
  • 11
    Do you realize that the above answer is what caused the creation of the `ClearConsole` plugin? Look at the comments. – Andrew Sep 25 '17 at 21:49
  • 5
    To others jumping straight to this answer - the `ClearConsole` package does not actually _clear_ the console, it just prints a bunch of newlines. – Taylor D. Edmiston May 08 '18 at 23:52
  • Taylor Edmiston is correct; the package name is misleading. When you copy the contents of the console, it will include everything before the newlines. – Synetech Jul 29 '18 at 03:23
  • @Andrew It should have a been an answer. Oh wait, that's what yujiezhang's just done here. – Joel Mellon Mar 04 '21 at 21:36
  • @JoelMellon I wasn't criticizing this answer! I thought it was cool so I was pointing out that the package yujiezhang was suggesting to install was actually created because of this question and the above answer. The creator of the ClearConsole package said that in the comments himself! Just incase him or anyone else didn't realize it! – Andrew Mar 08 '21 at 05:55
3

A new window will always have a clean console. You can use this to open a new window, close the old one and then reopen your project (assuming it is a saved project and not anonymous). This requires the hot_exit setting to be true, which is the default.

FichteFoll
  • 663
  • 1
  • 6
  • 12