3

I'm kind of new to software development. Outside of VSCode, I can open up a terminal (let's say PowerShell), run python in it, type in a command (like 2+2), be able to click the up arrow key to find my previous command so that I can run it again.

If I run PowerShell in VSCode and do the same thing, nothing happens when I click the up arrow where I would expect my previous command to be cycled.

Is this a problem with my Python or VSCode? I've been looking for a solution for this but haven't found many useful topics on this.

Sirius Sam
  • 33
  • 1
  • 4
  • Welcome to Stack Overflow, I don't think this is the expected behaviour, could you try with another shell (the default one for example, could you tell us more information about your system). If you think this is an issue on the VSCode side, you can raise an issue on the GitHub repository. – Benoît P Feb 20 '19 at 21:28
  • Thanks Benoit! Taking your suggestion, it actually worked a little. So in my original post, I actually ran PowerShell from Git Bash in VSCode (my default shell is Git Bash, so I commanded Bash -> PowerShell -> Python). In this instance of Python, I could not cycle to my previous command. I then set my default shell as PowerShell and ran python from there. It cycled to the previous command! What is the issue here? Seems like the issue here is bash since bash -> python does not remember the last command either. – Sirius Sam Feb 20 '19 at 21:46
  • Hey Sam. I included an answer below a couple minutes before you posted this that mentions that up-arrow autocomplete is a known issue with bash, especially on windows. that's what I figured it might be. Just use powershell when using VSCode and you should have no problem. –  Feb 20 '19 at 21:53

2 Answers2

2

This was going to just be a comment but its too long. Sorry it isn't more informative than it is. This is kind of an odd problem because VSCode isn't a true IDE. It doesn't have its own shell and just hijacks your powershell or bash terminal, depending on which OS you are using. You should be able to use your up and down arrows just like you can in powershell. I have tested it on my own VSCode installation and it works fine for me. If it's a problem, it's not with python, since VSCode will interact with the terminal the same way no matter which language you are using it for, so its probably with VSCode or your terminal. I have heard of others having issues with up arrow autocomplete in bash, so if you are connecting to a bash terminal that could be it, but I've never heard of it glitching in powershell. I'd say check which terminal you are using, see if the problem persists when you change terminals, and try reinstalling VSCode if it does. Past that, I don't know what to tell you.

  • The issue seems to be with bash (as I stated from the previous comment and your reply). Though I would like my default shell to be bash (for git stuff), seems like I would just have to deal with using PS. Thanks for the informative answer Jeremiah! – Sirius Sam Feb 20 '19 at 22:03
  • If all else fails you can just use VSCode as an editor and run your code natively from bash. I actually do this sometimes myself because VSCode can be twitchy when it comes to virtual environments and if I'm working out of one I find it less headache to use my native terminal. Also, I've only really heard of bash doing this in Windows so if you have a linux or mac machine you can work on your bash should work fine there. I'd say that the easiest thing to do would be to use powershell for basic things like serving and running code and use a native bash terminal to do stuff you need bash for. –  Feb 20 '19 at 22:08
  • An update: So I decided to add: alias python='winpty python.exe' , to the ~/.bashrc for a permanent alias to try testing it with the standalone bash terminal. I opened up VSCode and viola! Running python from bash (with it as the default shell) seems to remember the previous commands! Don't know why it worked, but I guess it should suffice. :) Thanks again for the info Jeremiah. – Sirius Sam Feb 20 '19 at 22:17
  • Nice. I actually just bookmarked this question. I'm having some build issues on a windows computer that I think would go away if I were using bash so I think I'm going to give this a shot. –  Feb 21 '19 at 21:52
0

I found a work-around. For me, neither git bash, nor PowerShell allowed up/down arrows for history switching within a python shell. So here it goes.

Ctr-Shift-P opens VSCode commands

Python: Create Terminal does not actuallt start python, but it does launch powershell in a mode that will enable us to succeed

py starts python shell with working up/down arrows!

KateYoak
  • 1,591
  • 3
  • 18
  • 34