I have a problem with python autocomplete in visual studio code. The only way I can trigger the autocomplete function is with the Tab or Enter key. Brackets and dot does not have any effect (or better it just hides the suggestion box and puts the bracket in place on the unfinished word e.g. -> typing pr in the editor would display the suggestion box with print as the first choice, if i then press bracket i end up with pr() instead of print())
I presume there should be some settings so autocomplete would act "normally" but I can't find it.
This is set by the shortcut key. Open the Default Keyboard Shortcuts (File > Preferences > Keyboard Shortcuts) and search for "acceptSelectedSuggestion". You will see that there are only two settings by default, the Tab and Enter keys.
If you want to add other buttons to trigger typing intellisense, right-click on one of the settings and select Add Keybinding,
then press the button you want to set, and press Enter to save.
I think you don't need to use the python autocomplete extension. You can just use the Python extension.
Tab or enter is required to actually make a selection. Otherwise, you could have custom function printStuff, and typing pr( would not necessarily pick the right one.
From what I can tell, PyCharm works the exact same way, so unclear what "acts normal" means in this context.
Related
In Corey Schafer's Programming Terms: Mutable vs Immutable, at 3:06, he selected multiple lines and commented them out in PyCharm all in one action.
What is this action? Is it a built-in shortcut in PyCharm that I can use or configure myself?
This is a setting you can change and define in "Settings".
The default is with Ctrl+/ for Windows, or Cmd+/ for Mac.
Years later: on AZERTY keyboard, '/' from syntax area (;.:/!§,?), AKA "slash" does not work!
You have to use the '/' symbol from numbers area (division symbol).
Is depends on you're text editor , but probably all text editor use (ctrl + /) just highlight all the code you need to comments and use the shortcut , to know what shortcut using in you're favorite text editor search in google : YourTextEditor shortcuts
If you use macbook build-in keyboard, this shortcut does not work. So you can assign new shortcut for this purpose by following steps;
1.Go keymap menu
PyCharm -> Preferences -> Keymap
2.Find "comment with line comment" then click pencil sign "add keyboard shortcut" then assign your custom shortcut (press your favorite keyboard combination)
This heavily depends on where you're writing your python code. If you're writing it in Notepad, there won't be a shortcut for commenting a line.
However, if you use an IDE, you will probably have such capability alongside the ability to change the shortcut.
Just search Google for keyboard shortcuts for your preferred IDE.
I've declared variable as a constant in the module beginning and some hundreds lines below I want to see it's value.
I know that it's possible to use ctrl and LMB to jump directly to declaration, but it's so distracting!
When I move mouse over variable's occurence with ctrl btn pressed I get only name and inferred type. I believe there is some way to see the value too.
I've found keyboard combination suitable for my needs.
Click on the variable somewhere in the code and use ctrl+shift+i to see constant's definition with all its values included. Especially useful if this const was imported from other module so you don't have to jump to the declaration source.
On Mac OS it is ⌥ + Space.
While you run your code in debugging mode use inline debugging functionality. This should lets you view the value of variables used in your source code right next to their usage, without having to switch to the Variables pane of the Debug tool window.
Enabling inline debugging
To enable it in Debug tool window toolbar click the Settings icon -> select the Show Values Inline option from the popup menu.
And then go to Data Views page in Setting/Preferences dialog select check box Show values inline.
I've just started learning python from scratch
I've installed 3.6 for windows
On the IDLE shell how can I get the shortcut for retyping what you previously executed (this is usually the up button)?
and also there is usually a drop down list for when you're typing something and python shows a list of what you might be about to type and you can select and it types it for you?
example:
thanks
To get last command executed, use alt+p.
Otherwise, under the Options menu, go to Configure IDLE >> Keys, and set history-next/history-previous to the keys you wish to use.
Press enter on the line you want to retype
EDIT
To show autocomplete window press TAB.
There's a default delay in 2 seconds. You can set popupwait to 0 in Options->Configure IDLE->Extensions->AutoComplete. Take into accout that you should restart you shell to activate new settings.
For Python 3.6 on Windows, specifically.
Shortcut to get what you typed previously: Alt + P
To get auto completion: Ctrl + space
Also, you can navigate the configuration for these Shortcut Keys in the Navigation bar.
All of the keybindings can be changed in Options > Configure IDLE > Keys. The ones in my answer are the default on Windows.
Cycle commands backwards: Alt+p
Cycle commands forwards: Alt+n
Alternatively, put cursor on a line you want to re-run and press Enter
Pop-up auto completion: Tab (or Ctrl+Space)
Alternatively, just set Options > Configure IDLE > General > Completions Popup Wait to 0, for the autocompletion to always come up automatically
The question is regarding Visual Studio Code (VSCode from here) and python VSCode extension that finds and runs py.test tests.
Is it possible to assign some shortcut to run current (under cursor) test method and/or test class?
I really like the ability to run single test straight from VSCode, but my workflow is not optimal since it is necessary to click it and just use some shortcut.
This image shows the buttons that appear when tests are found and can be run. I would like to know if it is possible to just use some custom shortcut instead of clicking this buttons.
Try Test Explorer UI and Python Test Explorer for Visual Studio Code.
The command list:
However, run-test-at-cursor doesn't work for me. I use run-file. Moreover, maybe you should join workbench.action.files.save, test-explorer.reload, and test-explorer.run-test-at-cursor with a macro extension.
Go to File > Preferences > Keyboard Shortcuts
In the searchbox, type python
All Python commands will be displayed below.
Select the command you want to add a key binding and click on the '+' button. Enter your preferred key combination in the new window.
Starting with VSCode 1.59 and the new Testing API (?) there are now these two new commands:
Run Test at Cursor
Debug Test at Cursor
Assuming the unit test you want to repeatedly run is selected in the Test sidebar (which you can do just by clicking on it), I've found a keyboard-driven option that doesn't require an extension to repeat running it. From anywhere in VS Code, type:
shift+cmd+i, which for me is bound to the command workbench.view.extension.test.
(Optional) Note that annoyingly, you sometimes have to press shift+cmd+i a second time to select the unit test in question (this seems like a bug to me - this happens with all Side Bar views)
Tab-Tab-Space (i.e. Tab, then Tab, then Space). The two tabs select the little bug symbol on your test and the Space kicks off another debug run of the selected test.
Here's how the screen should look after the two Tab presses:
and then the Space "clicks" the selected debug button.
With these 2-3 steps you can repeat this unit test ad infinitum.
HTH
In my case, a lot of test functions already have shortcuts:
I also added a shortcut to get to the test bench with the keyboard shortcuts utility.
Run/Debug/Interactive console in VSCode Editor ==>
File -> Preferences -> Extensions -> Robot > Code Lens: Enable/Disable
File -> Preferences -> Extensions -> Robot: Variables -> Edit in settings.json
need to add "ENV":"DEV"
Restart VS Code editor
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.