I basically want a workflow that goes like this:
I'm working on a script and run into some issues so I:
Move the script to the interactive console (shift+alt+e on Mac)
Run a few queries against my variables to figure things out. This step is over when I find a line of code that works.
Use a keyboard shortcut to add it to the end of the file I have open.
Repeat as necessary until I feel good about just editing the file directly again.
Options I'm aware of (that I don't care for)
Scroll up, copy, paste.
Use shortcut to open up history panel. Select line, copy, close panel, click on script, paste.
I feel it would be a lot smoother for my workflow if I could just hit some key combo and BAM! the last line of code I executed is just put at the bottom of the current file.
Can it be done? Anyone have some insight?
If you've just typed a statement, hit enter, seen that it looks right, and have an empty prompt waiting, you can:
Press the up arrow key to bring back the last statement
Press Cmd+A to select the whole statement
Press Cmd+C to copy
If the whole statement fits on a single line, you can skip step 2: in general if nothing is selected then Cmd+C copies the whole line at the cursor.
The prompt >>> or In[x] will not be copied.
You still have to click in the editor to paste, and I don't see a way around that. But at least for the copying you can save on some mouse movement.
Related
When I try to select all of the text in a file, I receive a notification that says:
(Ctrl + A) was pressed. Waiting for second key of chord...
Here is a screenshot of my "select all" keyboard shortcuts. How can I use Ctrl + A to select all text instead of getting a chord notification?
You have another key binding that begins with Ctrl+A, something like this:
A sequence of multiple keystrokes pressed one after another (rather than simultaneously) is called a "chord".
You might have accidentally created it, or might have recently installed an extension that adds the problematic binding. To find it, do like I have done in the screenshot and type "ctrl a" into the Keyboard Shortcuts search box (that tab can be opened by typing Ctrl+K then Ctrl+S). Then look for a binding that begins with Ctrl+A but has something else after it (in my case, another Ctrl+A, but it could be almost anything).
When you find the offending binding, right-click on it, and either remove or change it. Then Ctrl+A alone will resume working.
Note: This question and its answer pertain to Visual Studio Code, which is different from Visual Studio. See this question for information about the equivalent situation in Visual Studio.
You might be in a situation where you want to keep the chorded keybindings that are causing you the problem with your original keybinding. A potential workaround to this issue is turning your original keybinding into a chord as well. For example, you could having a 'stop' character that exits your chord. For example, "Ctrl+A ." where "." is your stop character.
So if for some reason you really liked "Ctrl+A" as the beginning keystroke for a bunch of chorded keybindings, then rebinding all current "Ctrl+A" keybindings to "Ctrl+A ." would free up that keystroke for any manner of other, chorded keybindings.
I was in a situation where Ctrl+x did not work and was considered the start of a keychord. Every time I pressed Ctrl+x, instead of cutting the selected text, the editor told me that it was waiting for the second key of the chord.
Looking at "Preferences->Keyboard shortcuts" did not help. Searching for Ctrl+X in the list showed that only the "Cut" command was mapped to this key.
I had to edit the file $HOME/.config/Code/User/keybindings.json (under Linux) and search for CTRL+x. It turned out another command was mapped to a keychord starting with this key combination. I am not sure know how I got in this situation.
In my case, reloading VS Code with extensions disabled fixed it, so I knew it was an extension. Took a while, but eventually figured out it was https://github.com/phsantos/nano-id-generator.
I am not able to click(I can say it's diabled) step in, step out, step over option in pycharm debugger
I don't know if this is exactly what is causing your issues but here is one possibility:
All debugging options are grayed out in the menu if your cursor is on an empty line or a line that is a comment. Try putting your cursor on an actual line with code. The "Toggle Line Breakpoint" option in the "Run" menu should now become active. After starting the script with "Run -> Debug", the breakpoint will be triggered (assuming the code reaches it) and the other debug options such as "Step over" become available.
As mentioned in this answer: https://stackoverflow.com/a/48665161/2891209
Depending on what you're trying to debug it is possible for step-in to not show you code which isn't pure python. Pycharm will do the best it can of course, but if the function you're trying to debug isn't native python be prepared for anything...
If you're trying to step into a python wrapped C library function
Sometimes the debugger will skip over that code completely.
Sometimes you can walk the frames but the editor can't show you lines of code.
Sometimes you'll be able to step into an empty skeleton of a function.
It really depends on how the library was created.
I'm having some trouble with pushing multi-line code chunks from a .py script to the interactive python pane in VS code. For reference, I'm moving over from using Rstudio as an IDE and would like the same sort of script-to-console interaction I'm used to from there.
For example, if I tried to run the following lines from a .py script:
def f(a):
print(a)
I'm able to run the def f(a): line, but rather than wait for the print(a) line to be run, the interactive pane tries to run the first line which results in:
IndentationError: expected an indented block (2416368674.py, line 1)
I am able to run multi-line chunks fine if I highlight the entire chunk and push it to the interactive pane.
I generally just want to be able to run multi-line chunks, functions, etc. line by line with the interactive pane knowing to wait if it should expect more code. I don't want to work with wrapping the code in a cell. Is there a way to fix this?
I am afraid you can not do that, it's unreasonable.
No matter you send the codes to the Interactive panel or the REPL in the terminal, it will automatically run the codes -- with an Enter press.
You want it without the automatically Enter press and wait for you to press it by yourself, or it can be smart enough to know when to keep waiting for the following codes.
But why not sends the code snippet directly instead of line by line and press the Enter automatically instead of manually press the Enter every time?
Apologies in advance for what should seem obvious to me...
New to Python, but other wise very experience, hence the frustration.
As I'm learning, I'm attempting to prototype the command at the command prompt (">>>") as I script. I can enter the python commands and validate they are correct, but (currently) then have to retype the command in to sublime, which seems inane, especially as I'm watching videos where they are copying and pasting one to the other...
Windows 7 CMD, & Python ">>>" command lines, Sublime window
I'm trying to copy commands from the Python command line ">>>" to the sublime editor in an open/new tab. Normally, I would mark/highlight the selection, then Ctrl+c, place the cursor in the target window (sublime in this case), Ctrl-v, and be done.
However, I'm unable to select what I want to copy (??). Up/down arrows will recall the individual lines (no problem with that) -- where I would usually do a Ctrl-(left/right arrow) to select the text, but no indication that anything has been selected. Same result using the mouse.
Thanks in advance for the assist.
This is an oddity of the Windows command prompt. First, there is a little bit of setup. Then you can do the cut-and-paste in a slightly different way than you are used to.
Setup
Right click on the title bar at the top. Select "Properties". Click on the "Options" tab. Make sure that the "QuickEditMode" box is checked. Close the Properties window.
Cut-and-paste should be enabled, but not using control-C to cut. Select the text you want to copy. Instead of typing control-C, just hit return (with the desired text selected). The text should now be on the clipboard to paste into other applications (with control-V)
In Linux terminals, pressing Ctrl+k copies everything in the line that follows the cursor. Ctrl+u copies the everything before the cursor.
Is there any way to make it so that I can press run and start typing the answer to the input prompt? It doesn't affect anything else, it's just really annoying having to take my hand off the keyboard every time
If you run your code using cells (which allow you to break your file in sections by using comments of the form #%%) then you can go to
Preferences > Editor > Advanced settings > Maintain focus in the Editor after running cells or selections
and deactivate that option to get the behavior you want.