Stop Matlab Command History From Jumping - matlab

Often I will want to repeat several Matlab commands from previous work, but not necessarily all at once. I can easily find these commands in the command history window and copy them across to the command window, but as soon as I execute these commands the command history window jumps down to the most recently executed commands, meaning that I have to scroll back up to find the section I was in for the remaining commands. Can I stop this jump from happening?

Related

How to get rid of the commands bringed by VS code terminal over and over

I have no idea why, but my VS code terminal keeps bringing in the history the same commands that I have used one day. So, every time I open the VS code, instead of bringing me the last used commands in that specific directory/project, it brings me the commands that I used once. It's the same commands, over and over.
That happens even if in the terminal is printed
**Session contents restored from 5/17/2022 at 3:29:45 PM**
They are actually not
Can someone help?

Is there a way to edit last Octave command and /or script typed in Octave CLI

typing and executing a single line command in octave cli is simple.
for example a=1.
If one wants to edit this command and execute it again it is possible by navigating the history with the up/down keys.
But when executing a multi line command-script, one can still navigate to a single line and edit it, but how to execute the all script again, without going line by line in the history and "enter" the line?
for example:
for i=1:6
a(i) = i;
end
Is there a way to open the all script in an editor, edit, and re-execute it?
Yes there is, via the history command.
E.g. history -q 3 will display the last 3 commands -- the -q switch means do not prepend line numbers, such that the output is copy-pasteable.
You can also use the -w switch to redirect the output to a file, which you could then modify in your editor and call as a script, as you suggest.
If you're using the GUI, you can also use the history pane to highlight the lines you're interested in (in the order that you want them!), and paste directly into the editor window.

Postgres Command line - clear/delete a query that I was in the middle of typing

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.

MATLAB code break

I have started running a script on MATLAB that takes days to finish. Usually, if I changed my mind and I don't want wait for it to finish and I get content with the intermediate results, I highlight the command window and press Ctrl-C to break the code.
Now, I have run MATLAB. But its desktop got kinda stuck in the background. When I try to restore the desktop from the toolbar, it does not restore. But I know from the task manager that the process is running and is consuming Memory and CPU performance. So, I am kinda stuck. I don't want to kill the process because I need the intermediate values in the workspace, and I can't open the desktop to break the code using ctrl-c.
Is there any solution? For example, is there any command that can be used in the command prompt to act as ctrl-c for MATLAB?
I am using MATLAB R2012b and Windows 8.
Quick try to fix the recent Problem:
Try ty set a higher priority to matlab.exe in the Task Manager. (Right click -> Priority -> Higher than normal). Then see if you can get the window to front.
Some approaches to avoid this problem in future:
Try to optimize your code. For starters look at: http://de.mathworks.com/help/matlab/matlab_prog/vectorization.html
Use Matlab compiler for faster execution: http://de.mathworks.com/products/compiler/
Include some drawnow commands at stratetic positions in the code. This allows matlab to process the Event Queue and capture ctr-C commands.
Save intermediate results to output files. For example you could write an output file all 30 min with your intermediate results. Easyiest way would be just save(filename). Then a .matfile with all your workspace variables is generated. You can than kill the process in the task manager, without loosing too much results.

Would it be possible to jump between prev/next Terminal command prompts?

I'm using zsh in OS X Terminal.app and for quite a while, I've been longing for a way to jump back and forth between prev/next prompts in the terminal's output.
One convenience with this would be to be able to review (and track errors at) the end of each command's output; eg. when you building stuff from source with ./configure; make; make install. Note: I'm obviously not referring to jumping back and forth in the command-history, but for a way to take a peek at the endings of each command's output.
Has anyone heard of such functionality in the *nix (preferrably also Mac) world? Would it require some sort of OS-centric Terminal plugin, or can it be programmatically done via a shell script which can be tied to a keyboard shortcut? Maybe I'm the only one thinking about this? :)
Edit: Here's an example scenario: Let's say I want to compile and install some program (using standard ./configure && make && make install procedure) and after the make command, I run into some errors. Now, the way I understand it (I may be completely wrong), the crucial error causing the make command to fail usually shows up in the last line(s) in the output, no? Anyway, at this point, I might do something like cat INSTALL to read up on the INSTALL document to check whether there's something I've missed. NOW, if I want to go back to see what the error was, that caused my initial make command to fail, I then have to manually scroll up to that position again, since my cat INSTALL command printed a ton of text after it.
I don't know if this scenario is the most elucidative – but there are many other situations where I wish I could just "jump" back to previous prompt lines and check up on previous command output; whether it was a simple ls command, make, git status, or whatever it was – swapping positions in the window by means of using prompt lines as "bookmark" positions seems an interesting idea to me.
command + left or right goes between tabs in iterm. is this what you are asking?
Emacs has a shell-mode that runs a shell inside the Emacs editor, providing a rich environment of additional commands for navigating and working with shell commands. This includes commands for going to the previous/next prompt, and deleting the output from commands so you can "clean up" and issue another command.
If you aren't familiar with Emacs: to start a shell inside Emacs, run emacs from the shell, then type Esc-x (or Meta-x, if you have "Use option as meta key" enabled in Terminal > Preferences > Settings > [profile] > Keyboard). This will ask for a command to execute. Enter shell.
To see a list of commands you can use in Shell Mode, enter Control-h m. Here are the ones for moving the cursor to the previous/next prompt:
C-c C-n comint-next-prompt
C-c C-p comint-previous-prompt
These commands would also be useful:
C-c C-r comint-show-output
C-c C-o comint-delete-output