Avoid VIsual Studio Code terminal to change its size when opening a file from it - visual-studio-code

In the Visual Studio terminal, having it expanded to full size (that is, it occupies the whole editor), if a file is opened by writing code <name_of_file>, the file will open and the terminal will be restored to a smaller size.
Is there any way to modify this behavior so, when opening a file, the terminal window either does nothing or it gets completely minimized and the focus is transferred to the new file editor?

After investigating a bit, as this youtube tutorialvideo explains, a partial solution for the problem above is using Panel: Opens Maximized. I say partial because, while that option will make the terminal always open maximized, if a file is opened from it, it will still be restored to a 'medium' size.

Related

Open Same VSCode File Buffer in Multiple Windows

Is it possible to open the same file buffer(editor) in multiple VSCode windows? This is not the same as opening the same file more than once. In the later, if you forget to save edits in one window, and then save different edits in another window, you end up with conflicts. I'm curious if it's possible to have the same buffer opened (mirrored?) in different windows, such that the view is identical for that file across all windows. So if I make changes in the file (even before saving), those changes also show in every other window that the buffer is opened in. I've searched around a lot but can't really find anything. Thanks.
Use the Split Editor command: Ctrl + \.
You can also use the icon in the top right. Hold Alt to split down.

How to get VSCode to "open as new file" from Go To File dialog

I have recently switched to VSCode, and am loving it, except for one specific thing that drives me nuts.
My "goto" command is {Command+P}, the easy search-and-open-file bar. If I type the name of a file into this bar and it does not exist, I want to be able to hit ENTER and have it open a tab editing that file as a new file. This is the behavior I would get in old-school Windows Notepad, or in mvim :e <filename>, but I can't figure out how to do it in VSCode.
Is there a toggle or a plugin I can use to get this behavior straight out of the Go To File dialog?
Answering my own question:
No, there's no way to do this using {Command+P}. This is strictly a file finder and I've yet to see any plugin that changes the behavior.
If you're using the VsCodeVim plugin, an almost-as-good approach is just :e <file> - immediately open a new buffer editing the given file. There's no tab autocomplete this way, but you just have to live with that.

How do you prevent VS Code from reopening file at previous scroll position

When using VS Code I'm experiencing unexpected behaviour. When I re-open a file, the editor opens at the previous scroll position.
Example:
I open a long file, scroll half way down make some edits, save and close the file
I reopen the same file again. It will open at the same scroll position where I made the edits half way down the file.
I expected that the editor would reopen the file back at the top of the file like in other text editors.
I haven't been able to find any settings that would explain this behavior.
just add the following line in the settings.json:
"workbench.editor.restoreViewState": false
unexpected behaviour
It is actually very much the expected behavior: restore the workbench in its exact state.
This is confirmed by issue 24394, which is asking (indirectly) what you want.
This behavior should be opt-in and disabled by default.
I often open a file, scroll to the bottom looking for something and close it then.
Now nearly every file I open starts at the bottom instead of the top and in 90% of the times the first thing I do is scroll to the top.
Commit 27cb886 from Sept. 2018, VSCode 1.28, introduces the setting
'workbench.editor.restoreViewState': {
'type': 'boolean',
'description': nls.localize('restoreViewState',
"Restores the last view state (e.g. scroll position) when re-opening files
after they have been closed."),
'default': true,
},
That fixes the issue.
Update August 2020, VSCode 1.49
Allow to configure workbench.editor.restoreViewState per language
When we close a file and then re-open it, VS Code will restore the cursor position.
In many cases this is desired.
However, in some cases it is not, therefore it would be useful to provide a setting for this and allow it to be configured differently depending on the language being used.
For example: when I run git commit in terminal, the COMMIT_EDITMSG file will open in VS Code.
Ideally my cursor would be positioned at the top so I can start writing my commit message right away. However, many times my cursor is positioned elsewhere, presumably because VS Code is trying to restore it to the position when I closed this file the last time I wrote a commit message.
This also happens when I run git rebase --interactive and the rebase todo list is opened in VS Code.
This is now fixed:
configure workbench.editor.restoreViewState for a language, e.g. markdown
open a couple of files including markdown and scroll + set a selection you can memorize
switch between tabs and verify view state is restored
reload window and do the same and verify view state is restored
close a non-markdown file and open it again and verify view state is restored
close the markdown file and open it again and verify view state is NOT restored
If you specify the filename when you run VScode. the file is shown at the beginning. For example, I have a file named 2gaussians.py. When I first started on this file I entered code at the command prompt on the command line. I opened my file from within VScode. I worked on my file and I quit with my cursor at the bottom of the file. When I ran VScode the next time I typed code 2gaussians.py on the command line. VScode opened and my file, 2gaussians.py, was displayed in the editor from line 1.

Visual Studio Code - Tabs (editors) of the same project in multiple screens

Using multiple screens I normally place multiple classes (files) in different screens, this helps me a lot while refactoring, checking tests and comparing changes.
Visual Studio Code does not allow me to drag a tab outside the window and view it in (for example) another monitor.
I checked the documentation and plugins, but the only way I found, is to open two windows, pointing to the same project (folder) and put those in different screens.
I don't like this solution, that causes also some problem when I watch code changes using TypeScript.
Any suggestion?
I use Windows 10, latest version of VSCode.
A solution is to press CTRL+K and after releasing CTRL, press O.
This will open the current file in a new window.
There are few things I don't like about this solution:
- Drag and Drop does not work
- Create a new instance of VS Code resulting in (for me) 180MB of ram used
- To open the file it takes to me few seconds (quite slow)
- The file remains open in the original window as well
Update 20/03/2019:
There is a feature request you can track here:
https://github.com/Microsoft/vscode/issues/10121
And an explanation about why this is difficult to implement here:
https://github.com/Microsoft/vscode/issues/10121#issuecomment-345770248
Update 20/03/2019:
Another important side effect highlighted by #Mär is that:
the IntelliSense fails to establish references it had when the file
was opened in the window, where the entire project is opened
The easy way but with the same drawbacks. More ram and resources will be used. Is to wrap your project in a folder.
It's the best possible thing. As by now!
=> Duplicate the workspace.
Open the command pannel ctrl+shift+p or F1.
Then write dupl
You'll get that
That's it.
More
If you want to add more folder to the working space.
=> go to File then Add Folder To Workspace
You can add as many as you like.
 Also better more
You can open a new window (ex: ctrl+n)
And then go File > Add Folder To Workspace.
And start adding folders to your new Workspace. You can add any folder, that is already open or not. That's too way great. You can have all the needed folders for example in the second screen.
A little hack I used is to just stretch the editor window to fill both screens and split the view pane between the monitors such that both screens show just one open file.
This is a cheap hack that works without opening multiple instances of VSC.
It may not be the proper solution, but it works without eating up all my system memory.
I found the following way to work on multiple monitors (important: they must be the same size and resolution):
open a visual studio in windowed mode on the 1st monitor (in my case it is a left monitor)
move the window to the (left) top corner
stretch window to the 2nd monitor (right) bottom corner
split screen by clicking “split editor” several times
move the code sections separator to the edge between the monitors
This is old qestion, but such way can be useful for someone. It is not very convenient, but it works. The solution may have already appeared in the VS itself, but I didn't find it.
Visual Studio Code does not allow me to drag a tab outside the window and view it in (for example) another monitor
Actually, VSCode 1.57 (May 2021, 4 years later) will propose something close:
Improved editor drag and drop across windows
Support for dragging editors to other windows was improved in this release. You can now drag diff editors, custom editors and the entire editor group to another window to open the editors there.
My solution was to use Remote-ssh to connect to self and open in another window. This does take extra resources. But I find this comfortable as I don't need to create additional workspace.
For me on Ubuntu the solution was to create a project folder symlink and ope it in a new window (as it won't open the same folder in another window)

How to set window size and position in Visual Studio Code?

Is it possible to set the VS Code window size and position, either via settings.json, though an extension, or by some other mechanism?
In Atom, I can do this in my init.coffee file as such:
atom.commands.add 'atom-workspace',
'custom:prepare-for-screencast': ->
atom.setSize(1280, 720)
atom.setPosition(37, 50)
Then I can call Prepare for screencast from the Command palette.
Not...yet?
https://code.visualstudio.com/docs/getstarted/settings
The closest I can find is window.newWindowDimensions, which only takes a few strings that refer to predefined geometries, although 'inherit' could serve you well in the meantime if you prime the pump by closing al your existing sessions, opening one window, sizing it to your liking, then quitting. Then all your new windows should be that size, and Visual Studio Code seems to be very well behaved with respect to resizing, just never close a resized window last, or it becomes your new default!
As for position, there appears to be nothing at all.
in vscode, go to
settins=>windw=>new window => new window dimension
there you are able to choose the following option to set the default dimensions, if vscode is getting opened:
inherit || offset || maximized || fullscreen
I prefer to use "inherit", i.e. open vs-code always as large as the previous one.
Start Visual Studio Code.
Click on "File"
Click on "Preferences"
Click on "Settings"
Write " window.newWindowDimensions " in the search box.
Select the value "inherit" from the drop down box.
That's it...!
If you're on a Mac, you can use this AppleScript snippet:
tell application "System Events" to tell process "Code"
tell window 1
set size to {1080, 720}
set position to {0, 0}
end tell
end tell
Not a general solution, but works well if you only need it when recording screencasts.
One way I found to solve this was by using the Developer Tools Console:
Help -> Toggle Developer Tools -> Console Tab
Type: window.resizeTo(1900, 1060);
Press Enter
Note: Tested on Windows 10, Ubuntu, OSX
Sidenote: Ubuntu had some strange behaviour bringing up the menu and developer tools. I had to open the developer tools while maximized, then undock the developer tools, then unmaximize the window, then type the command.
atom.commands.add 'atom-workspace',
'custom:prepare-for-screencast': ->
atom.setSize(1280, 720)
atom.setPosition(37, 50)
Then I can call Prepare for screencast from the Command palette.
This is really a good idea and a good feature to add to VSCode.
More important to me is "atom.setSize(1280, 720)"
Hope someone will be able to port this to VSCode.
"window.newWindowDimensions": "maximized"
Placing the following to settings.json is a good programmatical solution.
"window.newWindowDimensions": "offset",
The comment in the defaultSettings.json file says:
inherit: Open new windows with same dimension as last active one.
offset: Open new windows with same dimension as last active one with an offset position.
Basically the inherit option opens new windows completely overlapping to the current window, while the offset option opens new windows with around 50 px size of offset (depends on your screen size) from top/left.
I personally prefer "offset" but these two are essentially almost same.