On Unix Shell terminal, you can discard a typed command just by typing ctrl-c.
Is there a way to discard a typed command on Scala REPL?
Ctrl-C still works but it would exit the Scala REPL, which is probably not what you prefer.
A couple of cases:
If you're in the middle of a single-line command, you can hit Up button then Down to an empty command line.
If you're in the middle of a multi-line command and the command is incomplete, you can simply hit return a couple of times to let the REPL interpret the consecutive blank lines as intention to start a new command. But, in case you worry about whatever you've typed might get executed, safest way would still be to hit Ctrl-C.
When you're writing an unfinished block you can enter two blank lines and the REPL will then skip your command and start a new one.
You may then still use up buttons to retrieve the lines you want to continue with in the new command.
Related
Is there a way to quickly delete an entire query that I've been typing?
To clarify, this would be a query I'm still typing, not something that's currently running.
For example in bash, you can hit CTRL+C and it kills your current line, like:
$ typing some comman<CTRL-C>
After pressing CTRL+C it stops the previous stuff I have typed without executing.
It's just a thing I'm used to doing for quickly switching trains of thought ("oh what if I do this instead of this?"), but CTRL+C in the postgres terminal just terminates the process.
Aa alternative to Ctrl+C is Ctrl+ACtrl+K. While Ctrl+A moves the cursor to the beginning of the current line, Ctrl+K deletes all characters after the cursor.
This can be used in bash or many other UNIX commands, too.
I am using my keyboard to run an application in MATLAB, where each keypress is handled differently depending on the number or letter pressed. To recognize keypresses I'm using the HebiRobotics library discussed here:
Detect Keyboard Input Matlab
While running the program, hundreds of keypresses are required, each of which types a character in the command line, after the >>. Is there any way to delete these characters as they are typed so the command line remains clear? I've tried fprintf('%c',8) to backspace, but this applies to the previous executed command, not the characters on the current line.
To be honest, this isn't terribly important, but having the characters appear is ugly, takes a few extra clicks to delete, and is one of those little things that is driving me crazy.
This answer by 'Oleg Komarov' seems to be relevant -Clearing text typed with input() from command history
For example, place point at the beginning of a line with the text "foo bar". Then M-d C- C-e M-C-w C-w C-y produces " barfoo". This behaviour causes problems when I try to switch the order of text and when I combine a real kill with save-as-kill. No doubt prepending is often useful, but all the documentation I have found says that append-next-kill appends. How do I control emacs's choice between appending and prepending?
See the Emacs manual, node Appending Kills. It gives explicit examples, in particular an example that shows clearly what C-M-w is for and what it does. Here is part of that text:
If a kill command is separated from the last kill command by other
commands (not just numeric arguments), it starts a new entry on the kill
ring. But you can force it to append by first typing the command
`C-M-w' (`append-next-kill') right before it. The `C-M-w' tells the
following command, if it is a kill command, to append the text it kills
to the last killed text, instead of starting a new entry. With
`C-M-w', you can kill several separated pieces of text and accumulate
them to be yanked back in one place.
For C-M-w to append the next kill, that kill must immediately follow C-M-w. If you do something else in between then there is no appending. The command name might better have been append-next-kill-if-it-follows-immediately. ;-)
I want to be able to send entire files and selections to the SublimeREPL and eval them, but it doesn't work. CoffeeScript REPL will only read one line at a time.
Coffee will only take single lines, until you use ctrl+v to switch CoffeeScript to multiline (which works in Terminal), but is blocked by sublime's interface... I'd really like to be able to eval more than one line using SublimeREPL's "ctrl+, s", "ctrl+, f" key bindings. There seems to be no direct way to open coffee with multiline mode automatically.
Maybe I'm going about this wrong, but it's only reasonable that I could use multiline JS Object notation in a CoffeeScript file, for example, and then test it in the REPL. I do it in Python and straight up Node all the time.
You need to be able to switch multi-line on then off again, so ideally if I could edit Sublime REPL to run that key shortcut ( ctrl+v ) before and after running a snippet of code that would be the best.
SublimeREPL v2.0.9 will fix your problem using multiline hack in repl.coffee.
[Ctrl+, s] and [ctrl+, f] should work as expected now :)
Release notes: https://github.com/wuub/SublimeREPL/releases/tag/2.0.9
repl.coffee http://coffeescript.org/documentation/docs/repl.html#section-2
I made a plugin: https://github.com/billymoon/Sublime-Pipe-Dream/ which aims to do this - and much much more. It needs patching up a bit - so any help appreciated. I use it on my mac with sublime text 2 to pass arbitrary selected text, or whole buffers (not saved files) to shell commands and either display the result in the console, or replace the selected text with the console output.
This is very handy for converting coffee to js, js to coffee, executing js/coffee/sql, beautifying and uglifying code and anything else where you want to pass text through a command line script.
In Matlab, there is a very nice feature that I like. Suppose I typed the command very-long-command and then a few several commands afterwards. Then later if I need the long command again, I just type very and press the up arrow key, my long command appears. It finds the last command that starts with very. I couldn't do the same in unix command line, when I try to do it, it disregards whatever I typed, and goes back to the last commands in chronological order. Is there a way to do it?
In bash this functionality is provided by the commands history-search-forward and history-search-backward, which by default are not bound to any keys (see here). If you run
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'
it will make up-arrow and down-arrow search backward and forward through the history for the string of characters between the start of the current line and the point. See also this related Stack Overflow question.
In bash, hitting ctrl-r will let you do a history search:
$ echo 'something very long'
something very long
$ # blah
$ # many commands later...
(reverse-i-search)`ec': echo 'something very long'
In the above snippet, I hit ctrl-r on the next line after # many commands later..., and then typed ec which brought me back to the echo command. At that point hitting Enter will execute the command.
You can do the same thing by using "!". For example:
$ echo "Hello"
Hello
$ !echo
echo "Hello"
Hello
However, it is generally a bad idea to do this sort of thing (what if the last command did something destructive?). If you expect you will reuse something, then I suggest you create a shell script and save it away somewhere (whenever I plan to reuse something, I create a script in ~/.local/bin).