How to clear screen in Windows command prompt window with a hotkey? - windows

I have searched a lot to find a way (keyboard shortcut) to clear the screen of the console window of cmd on Windows 10. I tried Ctrl+L and Ctrl+K and ESC, but nothing worked for me and I didn't find any satisfied solution.
Thanks a lot for the AutoHotkey script.
I modified the script to input Python script to clear the screen when using scrapy shell like that
Send from os import system{Enter}
Send cls = lambda: system)'cls'({Enter}
Send cls)({Enter}
It worked well but I noticed the value 0 at the top of the window.
The console window after execution of AutoHotkey script with █ as blinking caret symbol.
0
>>> █
How can I remove that zero?

The simplest way of clear window in command prompt is typing: cls + enter
Ecs is a key to exit input of command prompt, it does noting on clear window
Ctrl + L and Ctrl + K are not correct short key in Linux command prompt. If you really want to make it a short cut key of cls, you can use AutoHotKey to write a short script
; -------------------------------------------------------------------------
; Cntr-L should clear screen
; -------------------------------------------------------------------------
#IfWinActive ahk_class ConsoleWindowClass
^L::
Send cls{Enter}
return
#IfWinActive
Official website of autohotkey: https://www.autohotkey.com/
Windows 10 + python 3.9 clear command prompt script:
import os
os.system('cls')

Related

Repeat last command windows terminal

On the Windows Terminal, is there a way to repeat the last command by starting character, similar to the feature on a Unix Terminal?
For example, if I type the command cd .. then laster type !cd on a Unix Terminal, it will do the command cd .. again. However, I can't find this feature on the Windows Terminal.
EDIT: Here is the terminal I am using (as installed by Windows, no specific configurations):
EDIT: I am aware that pressing the up/down arrow can navigate the history of commands, but I am in a situation where I use a multitude of different commands and use the arrow keys every time can be tedious. Accessing last command by starting letter will be a lot more useful, similar to the ! command on Unix mentioned above.
Two Solutions
Ctrl + r, then type initial letter(s)
type initial letter(s), then F8
If you are using PowerShell or Bash on your Windows Terminal, you can use a feature called Reverse Search. This will go through your history backwards and show you the recently used command based on the starting characters.
In order to activate reverse search, press Ctrl + R on the terminal and type out the initial characters and watch the recent command appear.
Bonus tip: You can press Ctrl + R further to show next recent command
Note: This does not work for Command Prompt (cmd.exe)

what is shortcut command to kill process in windows command?

Problem :
I have a process in windows command which cannot be killed. I tried taskkill and all the shortcuts in this post
Linuxlike Ctrl-C (KeyboardInterrupt) for the Windows cmd line?
It refuses to die, even Windows task manager doesn't work to kill the command prompt. This program is resistant.
Ctrl + C should stop a program running from the command prompt, similar to linux.
If that doesn't work try to force kill a process from the command prompt, using the following command:
taskkill /F /IM process.exe
/F will force termination of the process, /IM means you're going to provide the running executable that you want to end, thus process.exe is the process to end.
tried using alt + F4?
I was in a similar situation where exit() and Ctrl+Z were the commands used to escape.
Typically entering exit (or logout) will provide you with assisting information, in my case I had the following output:
Use exit() or Ctrl-Z plus Return to exit
In Windows:
First try: Ctrl + C If it doesn't work then try pressing q
In MAC OS:
Press Cmd + C or Ctrl + C or q

Open a small window while in Vim for executing commands

I need to write lot of code and compile very often. I hate switching back and forth various windows just to compile the code. Is it possible to open a small window at bottom and run invoke shell and close that window when needed?
With GVim or MacVim, you can run external commands in the command-line: Gvim/MacVim comes with a (very) limited shell that will happily show you whatever the compiler outputs. The general usage pattern is:
:!command
:!command %
With CLI Vim, the same method will pause Vim and return to the shell to execute your command.
In both cases, you'll get a message asking you to press ENTER to come back to your normal editing.
Using :make | cw would be a slightly more sophisticated alternative, with the added bonus of showing the errors in the quickfix window.
An even more sophisticated approach would be to use Tim Pope's Dispatch plugin in combination with tmux or screen.
Sounds like a problem for Screen
http://www.gnu.org/software/screen/
Quick reference of commands
http://aperiodic.net/screen/quick_reference
I use tmux to achieve something like that. I have the following in my ~/.tmux.conf file:
bind s splitw -v -p 25 -c '#{pane_current_path}' '/bin/bash'
bind q kill-pane
On pressing Ctrl-b + s (prefix + s), a new pane containing a bash shell opens up at the bottom. I can run shell commands from there: find, grep, make, etc. When I'm done, I press Ctrl-b + q to close the shell.
To enable tmux on every bash session, add the following to your ~/.bashrc:
[[ -z "$TMUX" ]] && exec tmux
Maybe map a key to shell out to the compiler and run the program if compilation is successful:
:map F8 :!cc % && ./a.out
Or maybe just
:sh
make run
Ctrl-D
Another option is to suspend vi, using Ctrl-Z and do your stuff in the shell, then type fg to bring vim back to the foreground. Note that this is actually a feature of your shell, rather than vim but it produces the effect you seek.
Note this idea originates from the book "Efficient Linux at the Command Line" by Daniel Barrett. I forget the page number.

xdotool output lost in iTerm2

I am running Mac OS X 10.7.5. I have installed XQuartz v2.7.4, and along with it X11 v2.6.5. I have started iTerm2 with Xserver, and I believe it's working correctly since when I run xdpyinfo, the beginning of the output in xterm and in iterm2 is the same.
█ $xdpyinfo
name of display: :0
version number: 11.0
vendor string: The X.Org Foundation
vendor release number: 11006000
X.Org version: 1.10.6
...
However, when I run any xdotool commands in iTerm2 the output does not show up in the same window:
█ $ xdotool key f
█ - MacBook-Air:~ ()
Whereas, when I run from xterm:
bash-3.2$ xdotool key f
fbash-3.2$ f
So I can tell that in xterm the output from the command is going to the right window, but that doesn't seem to be the case for iTerm2. Please let me know if you have an idea of what I may be doing incorrectly or missing. Thanks!
The problem is that iTerm2 is not an XQuartz client, and while you are typing the commands, there is no current XQuartz window (since MacOS's focus is on the the iTerm2 window — not an XQuartz window.
The xdotool manual page tells you that the key command has an option which would be used to redirect events to other windows:
--window window
Send keystrokes to a specific window id. . You can use "WINDOW
STACK" references like "%1" and "%#" here. If there is a window
stack, then "%1" is the default, otherwise the current window
is used.
If you gave it a valid window id using --window, it likely would work as intended.

How can I clear previous output in Terminal in Mac OS X?

I know the clear command that 'clears' the current screen, but it does this just by printing lots of newlines - the cleared contents just get scrolled up.
Is there a way to completely wipe all previous output from the terminal so that I can't reach it even by scrolling up?
To clear the terminal manually:
⌘+K
Command+K for newer keyboards
To clear the terminal from within a shell script;
/usr/bin/osascript -e 'tell application "System Events" to tell process "Terminal" to keystroke "k" using command down'
A better way to clear the screen from within a script...
If you're using the OS X Terminal app (as stated by the OP), a better approach (thanks to Chris Page's answer to How do I reset the scrollback in the terminal via a shell command?) is just this:
clear && printf '\e[3J'
or more concisely (hat tip to user qiuyi):
printf '\33c\e[3J'
which clears the scrollback buffer as well as the screen. There are other options as well. See Chris Page's answer to How do I reset the scrollback in the terminal via a shell command? for more information.
Original answer
The AppleScript answer given in this thread works, but it has the nasty side effect of clearing any terminal window that happens to be active. This is surprising if you're running the script in one window and trying to get work done in another!
You avoid this by refining the AppleScript to only clear the screen if it is frontmost by doing this (taken from MattiSG's answer to How do I reset the scrollback in the terminal via a shell command?):
osascript -e 'if application "Terminal" is frontmost then tell application "System Events" to keystroke "k" using command down'
... but as when it's not the current window, the output will stack up until it becomes current again, which probably isn't what you want.
To delete the last output only:
⌘ + L
To clear the terminal completely:
⌘ + K
The pretty way is printf '\33c\e[3J'
Put this in your .bash_profile or .bashrc file:
function cls {
osascript -e 'tell application "System Events" to keystroke "k" using command down'
}
On Mac OS X Terminal, this functionality is already built in to the Terminal Application as menu View → Clear Scrollback (the default is CMD + K).
So you can re-assign this as you like with Apple's Keyboard shortcuts. Just add a new shortcut for Terminal with the command "Clear Scrollback". (I use CMD + L, because it's similar to Ctrl + L to clear the current screen contents, without clearing the buffer.)
I am not sure how you would use this in a script (maybe AppleScript as others have pointed out).
With Mac OS X v10.10 (Yosemite), use Option + Command + K to clear the scrollback in Terminal.app.
Or you can send a page break (ASCII form feed) by pressing Ctrl + L.
While this technically just starts a new page, this has the same net effect as all the other methods, while being a lot faster (except for the Apple + K solution, of course).
And because this is an ASCII control command, and it works in all shells.
Command + K will clear previous output.
To clear entered text, first jump left with Command + A and then clear the text to the right of the pointer with Control + K.
Visual examples:
Do the right thing; do the thing right!
Clear to previous mark: Command + L
Clear to previous bookmark: Option + Command + L
Clear to start: Command + K
clear && printf '\e[3J'
clears out everything, and it works well on OS X as well. Very neat.
I couldn't get any of the previous answers to work (on macOS).
A combination worked for me -
IO.write "\e[H\e[2J\e[3J"
This clears the buffer and the screen.
Adding the following to your configuration file would get you a new command to do it.
alias clearwipe='printf "\33c\e[3J"'
After reload clearwipe would be the new command to completely wipe all previous output from the terminal so that you can't reach it even by scrolling up.
Typing the following in the terminal will erase your history (meaning using up arrow will get you nothing), but it will not clear the screen:
history -c
CMD + K works for macOS. It clears the entire terminal output, but the environment remains.

Resources