How to open VSCODE with new file from command line and preserve prior state? - visual-studio-code

Using Visual Studio Code (latest version as well as prior versions), when using the command line to launch I am seeing some odd behavior. Trying to determine if I am missing something, or if this is a bug.
Here is the scenario.
Action 1: I have a workspace open with a couple of files open for editing. If I close VSCODE, and then just open it again the state is restored, I am in the workspace and the files are open for editing. Great.
Action 2: I have a workspace open with a couple of files open for editing. If I then from a command line do "vscode testfile.txt" then the new file gets opened in VSCODE and joins the other opened file. Great.
Action 3: I have a workspace open with a couple of files open for editing. I close VSCODE. I then from a command line do "vscode testfile.txt". VSCODE starts up, but only the new file gets opened in VSCODE. The workspace I had opened is not any more, and the files I had opened are no longer opened. Not so great.
I have tried adding the -r option on the command line but that didn't change anything.
This feels like a bug, but if not help me understand how I get the desired result, which is when VSCODE is not running, and I try to edit a file from the command line, I want VSCODE to restore to the state it was in when last closed, and then add that new file to the mix. Just like if it was already running.

Related

VScode opens three empty files named "visual", "studio", and "code"

I open a file on a BeagleBone Black running debian 8.4 with VScode via SFTP with winSCP. By right clicking > edit > code.
When the file opens, VScode also opens three new files named visual, studio, and code (image attached). I did not create these files myself. Opening files from other sources does not cause this.
I have tried closing the files individually. Connecting and reconnecting. Opening and closing VScode. In every possible order and configuration. They return every time when opening another file with the same method.
This is how I have set up VScode as an editor in WinSCP.
This is extremely odd, and only trivial, yet highly annoying.
What's causing this? How do I stop it?

How to open a file in the current open Eclipse workspace from command line?

I have Eclipse already running, and I want to be able to open a file and jump to a line number from CLI.
I want the file to open in the current open workspace. I am trying this:
/Applications/Eclipse.app/Contents/MacOS/eclipse --launcher.openFile test_file.c:401
However, I am getting an error because the default workspace is already open, and its asking me to choose another workspace.
if I simply use open text_file.c it works just fine, but doesn't jump to the line number of course.
Edit: Even after starting in a new session, and removing the line number, Eclipse doesn't open the file. It only opens the application (Eclipse).
however if I use open -a eclipse filename the file opens successfully
Thanks to Lili for the correction:
Opening a file in the same workspace via command line does not work on mac, bug1
Opening a file/linenumber in eclipse is not supported

Visual Studio Code doesn't reopen files or folders

I usually open files in VSCode using command line. When I close it with many tabs and folders opened and try to launch it as code blah, it opens only the blah file, without restoring all of the previous opened ones.
Is there a way to force it restore everything ?
Just run code to reopen the previous window
Running code X will open just file/folder X. This behavior is by-design but we may add a flag to control it at some point

re-open vscode without last workspace or last files

I wish set VSCode to be launched clean, no last workspace or last files opened..
is this possible?
I use it as unity3d debugger and annoying me all the times that opens a previous workspace (no workspaces saved)
thanks in advance
Besides my comment above, also see open a new window, v1.22 released today if you prefer to open via a command line.
Controls if a new empty window should open when starting a second
instance without arguments or if the last running instance should get
focus. // - on: open a new empty window // - off: the last active
running instance will get focus // Note that there can still be
cases where this setting is ignored (e.g. when using the -new-window
or -reuse-window command line option).
"window.openWithoutArgumentsInNewWindow": "on"
But the setting
"window.restoreWindows": "none"
should also work for opening in other ways (but seems to require a few restarts - perhaps it has been fixed as of 1.22?).
According to the VSCode command line documentation, you can use -n or --new-window flag to open new session without any old files.
I just checked and it works.
The full command to run VSCode is (on my PC):
"C:\Program Files (x86)\Microsoft VS Code\Code.exe" -n
or just
code -n
Tip: You can change the shortcut for VSCode to include the -n flag so it opens new session always.
None of the other solutions were working for me.
Recently hit this issue where I tried to do a find and replace with 15000 files and vscode crashed while trying to save all those files. I closed the window and re-opened but it kept trying to re-open those 15000 files and would crash again.
I was able to fix this by deleting the corresponding workspace folder (search by folder name) in
/Users/{username}/Library/Application Support/Code/User/workspaceStorage
Then when you reopen that folder nothing is saved or open.

VS Code open last files

I gave a chance to Visual Studio Code as my primary editor. I had been using Notepad++ and afterwards I have been using Sublime Text 2 and 3 for few years. I do see potential of this editor and I really like it, but there is one thing I am strongly used to.
Notepad++ and Sublime Text has this feature, I can edit file and DON'T save it anywhere. After restart Notepad/Sublime Text this file is there ready for me.
Other workflow could be open any file from my local storage, close VS Code and start it again. This file will not open!
I know about that when I open folder and restart VS Code, folder is open and files as well. But is there any way how can I manage to have opened files after restart without having opened folder?
Edit: This is now implemented:
// Controls whether unsaved files are remembered between sessions, allowing the save prompt when exiting the editor to be skipped.
"files.hotExit": "onExit"
I use the insider release, and in the current version (1.3.0), vscode doesn't keep unsaved file. I think there is a feature request for that.
Got it: https://visualstudio.uservoice.com/forums/293070-visual-studio-code/suggestions/8568343-keep-unsaved-files-after-crash
You can vote for that feature, like I did !
On the other hand, You can tell in settings if you want to re-open previously opened folders, but not files.
"window.reopenFolders": "all"