How can I keybind opening a new terminal to the right of my current opened files? - visual-studio-code

Currently I have the below snippet of code that doesn't really seem to do what I want it to do under my vim normal mode keybinds:
{
"before": ["<Leader>", "f", "t"],
"commands": [
"workbench.action.terminal.newInActiveWorkspace",
"workbench.action.terminal.focus",
"workbench.action.moveEditorToNextGroup"
],
"when": "editorTextFocus && !terminalFocus && !quickInputVisible"
},
I want it to open up a new terminal tab, and open it as a new tab of the files which are opened in the middle of VS Code (not on the bottom terminal part).

It sounds like you want one of these commands:
Terminal: Create New Terminal in Editor Area
workbench.action.createTerminalEditor
Terminal: Create New Terminal in Editor Area to the Side (i.e., as a split/new group)
workbench.action.createTerminalEditorSide

I'm not aware of a VS Code command to change the location of a panel or open a panel in a specific location.
I do know that you can change the default location of all the panels by doing something like "workbench.panel.defaultLocation": "right". You might need to close and reopen VS Code after changing that setting for it to take effect.

Related

How to open file from VSCode file explorer in same window

Using cmd+shift+e I can highlight the file explorer tab and then use vim keybindings to select a given file. However, I've only figured out how to open a selected file in a new editor pane (Ctrl+Enter).
Is there a shortcut to open it in the same pane? Can I change the behavior of the Ctrl+Enter shortcut? A pointer to the right docs would also be helpful.
This closest action is filesExplorer.openFilePreserveFocus, which is bound by default to Space.
This will open the file currently selected in a new tab, but it won't move your cursor to it.
You can use the cmd+shift+e keybinding to get back to your editor, though!
From the docs
The settings window.openFoldersInNewWindow and window.openFilesInNewWindow are provided to configure opening new windows or reusing the last active window for files or folders and possible values are default, on and off.
If configured to be default, we will make the best guess about reusing a window or not based on the context from where the open request was made. Flip this to on or off to always behave the same. For example, if you feel that picking a file or folder from the File menu should always open into a new window, set this to on.
Note: There can still be cases where this setting is ignored (for example, when using the -new-window or -reuse-window command-line option).
The filesExplorer.openFilePreserveFocus command does what you want with the limitation that it keeps the focus on the explorer sidebar. To move focus to the opened window you can utilize the fact that workbench.view.explorer toggles focus between editor and explorer. Together with a extension such as multi-command that enables running multiple commands the desired behaviour can be achieved:
{
"key": "enter",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"filesExplorer.openFilePreserveFocus",
"workbench.view.explorer",
],
},
"when": "explorerViewletFocus && explorerViewletVisible && !inputFocus"
},

VSCode: keep focus in folders panel after selecting a file

I want to be able to navigate files in VSCode workspace efficiently via keyboard: exploring the repo by looking at dozens of files before I find a good one.
I can highlight some file in the Folders view by clicking it, then I use arrows to navigate around (so far so good), but when I click Enter, the file is opened and the editor takes focus - which prevents me from navigating the tree further.
Is it possible to configure VSCode so that editor does not take focus after I open it from the sidebar?
The best I found so far is that it is possible to create a key binding to bring back the focus to explorer: ctrl-shift-p > Preferences: Open Keyboard Shortcuts > look for workbench.explorer.fileView.focus (by default there's no key binding assigned).
[EDIT}: As of v1.38 a new command has been added that allows you to open an explorer file and keep focus in the explorer:
Open file and preserve focus
Now it is possible to open the file in preview from the explorer while
preserving the focus in the explorer. The new command is
filesExplorer.openFilePreserveFocus and by default it can be triggered
via the space key.
from open file and preserve focus
[Original answer - now see edit above]
You can do this in one step with a macro extension which enables you to run two commands with the enter key. Here I am using the multi-command extension which has an interval delay option. A 150ms delay between the commands seems necessary to allow the file to be opened before switching focus back to the file explorer.
"multiCommand.commands": [
{
"command": "multiCommand.openFileKeepFocusInExplorer",
"interval": 150,
"sequence": [
"list.select",
"workbench.explorer.fileView.focus",
]
}
]
And then assign a keybinding (in keybindings.json) to that multi-command:
{
"key": "enter",
"command": "multiCommand.openFileKeepFocusInExplorer",
"when": "sideBarFocus && activeViewlet == 'workbench.view.explorer'"
},
In the demo below, I am only using the arrow and enter keys to move between files, open them and keep focus in the file explorer:

Is it possible to make an editor split full-screen in VSCode?

I'd like to have the ability to make one of multiple split editor windows full screen.
I usually have two vertically splitted windows with code and it would be useful to make sort of full-screen-zoom without explorer terminal and all other bars, just code.
Initally I have the following:
but I would like to configure a shortcut to make an active window full-screen like this:
It is like F11, closing the explorer, and merging the split. It is messy to do it by hand all the time...
I would like to configure a shortcut to make an active window full-screen.
You need to edit keybindings. Press Ctrl+K and then Ctrl+S to open keyboard shortcuts.
If you're on a mac, use Command key instead of Ctrl.
Search full screen in search bar. You will see something like this:
Click on the result. Press Ctrl+K and Ctrl+K (again!) or click pencil icon to edit the shortcut. Press desired key combination. That's it.
And here are some more shortcuts to learn:
Press Ctrl+K and then Z to open editor in full screen without explorer and terminal, etc. And you can use Ctrl+B to show/hide side bar and Ctrl+J to show terminal and console panel.
Download keyboard shortcuts file here for your favourite OS.
To make these hotkeys work in vim-mode:
Actually VSCodeVim will take over your control keys. This behaviour can be adjusted with the useCtrlKeys and handleKeys settings. Go to File>>Preferences>>Keyboard Shortcuts. Search for Ctrl+k in search bar. You will see extension.vim_ctrl+k as below:
Change this hotkey. Now it should work.
The closest you can get to maximize ONE EDITOR GROUP out of two open editor groups,
(capitalizing because nobody read the actual question properly!)
is to set this command as a shortcut:
View: Toggle Editor Group Sizes
workbench.action.toggleEditorWidths
which will toggle the active editor group to 90% of the screen
If you have the side bar open that will take up another 10%,
to close that automatically use:
View: maximize Editor Group and Hide Sidebar
workbench.action.maximizeEditor
(this command doesn't toggle so you still need the previous shortcut)
(and also now your sidebar is closed when you toggle back)
To achieve maximum fullscreen vibe, use Ctrl-k z to enter zen mode, the sidebar, terminal, menus and clutter disappear,
leaving just the editor groups, which you can toggle their size with the previously mentioned shortcut.
Don't get lost in zen mode! It happens, remember the shortcut Ctrl-k z
Not ideal,
I think we'd all prefer to have dedicated toggles for zen-moding the active group editor or file 100%,
but it's close enough for now.
Here's a screenshot of it in action:
VS Code Editor Full Screen Without Explorer and Terminal - Press Ctrl + K then Z (Zen Mode)
To exit from the full screen mode, press Esc two times.
I use this on OSX, hope it will be helpful. Just replace command code with codef.
#!bin/sh
codef() {
code $* && sleep 0.5 && /usr/bin/osascript -e \
'tell application "Visual Studio Code"
activate
tell application "System Events"
keystroke "f" using {control down, command down}
end tell
end tell'
}
In windows to exit vscode full screen mode, press key
F11
To go back again into full screen mode, press key
F11
the upate June 2021 from VS Code can move the terminal inside the editor area
Step 1
The new terminal.integrated.defaultLocation setting can be set to editor to direct newly created terminals to the editor area by default.
Step 2
With the Zen-Mode -> Strg + K + Z you get the full window terminal experience.
This solution is close to what was originally asked. I edited some vscode settings and now I can switch between 2 states quickly:
State 1: have multiple (equal sized) editor splits open, maybe a terminal and the sidebar
State 2: have the current editor split bigger and the terminal and sidebar removed, at the same time vscode maximized to fullscreen
To toggle I use Ctrl+Alt+Z and then Ctrl+Alt+B. To go back I type it in reverse order.
To make it work I inserted the following into my ~/.config/Code/User/keybindings.json:
{
"key": "ctrl+alt+b",
"command": "workbench.action.toggleEditorWidths"
},
{
"key": "ctrl+alt+z",
"command": "workbench.action.toggleZenMode"
},
{
"key": "ctrl+k z",
"command": "-workbench.action.toggleZenMode"
},
It works for me in VSCode version 1.61 on Linux. On a Mac it would probably need some adjustments. On Windows it should be the same.
There is still a minor problem: After returning from zen mode, the cursor focus has moved to the terminal window, which is annoying and probably a VSCode bug. To solve it and return to where you were, using only the keyboard. if you have two splits, type:
Ctrl+1 for the first split or Ctrl+2 for the second
We can improve on #bevo099's answer by adding keybindings.
This will cause F11 (the fullscreen key by default) to instead zoom-in on the active editor or terminal panel. Zen mode is already full screen, so it replaces well.
I used the multi-command extension to allow multiple actions on one binding.
In keybindings.json:
[
{
"key": "f11",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.toggleEditorWidths",
"workbench.action.toggleZenMode",
]
},
"when": "editorTextFocus && !inZenMode"
},
{
"key": "f11",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.toggleZenMode",
"workbench.action.toggleEditorWidths",
]
},
"when": "editorTextFocus && inZenMode"
},
{
"key": "f11",
"command": "workbench.action.toggleMaximizedPanel",
"when": "terminalFocus"
}
]

VSCode keyboard shortcut for optionally triggering keepEditor when using quickOpen?

VSCode by default binds cmd+p to workbench.action.quickOpen. Which is fine. My only issue is that when you confirm a quickOpen on a file using enter it opens the file in a “preview” mode (indicated by the tab’s name having an italic font). This “preview” mode means that if I open two files in a row using cmd+p the action of opening the second will take over the “preview” slot, effectively closing the first file's preview.
VSCode has a setting called workbench.editor.enablePreviewFromQuickOpen which you can use to change this behavior globally. But I don’t want to change it globally. You can also manually move a file out preview mode using workbench.action.keepEditor which is bound by default to cmd+k+enter. But that's an obnoxious extra step.
I would like to selectively decide when I want to open in “preview” mode or in “edit” mode. Ideally I would like to bind something like shift+enter to do this. In my keybindings.json have tried variations on
{
"key": "shift+enter",
"command": "workbench.action.keepEditor",
"when": "inFilesPicker && inQuickOpen"
}
but with no luck :(
The answer to this question ALMOST does what I want:
vscode: Open file instead of previewing file from quick open
The proposed solution of using alt+enter opens the file in a new window. No bueno.
The proposed solution of using the right arrow key to open the file does work... but it does not close the Command Palette like hitting enter does. No bueno.
I do believe you will have to use a macro extension like multi-command. In your settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.openFileNotInPreview",
"sequence": [
"workbench.action.acceptSelectedQuickOpenItem",
"workbench.action.keepEditor",
]
}
]
In keybindings.json some keybinding:
{
"key": "shift+right",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.openFileNotInPreview" },
"when": "inFilesPicker && inQuickOpen"
},
I used "shift+right" here, your "shift+enter" seemed to run into conflicts and would not work.
This will open your selected file in the Ctrl-P panel in a new editor in your same editor group and it will not be in preview mode.

Toggle between fullscreen editor and terminal in VS Code

As a Windows systems admin, I use PowerShell quite a lot. With the release of PS Core, and the implication that the ISE is dead, I've started to try to use VS Code as my day to day tool. One feature I'm missing from ISE is the ability to swap between the editor and the terminal in fullscreen. I usually kept ISE open and maximized, and used Ctrl+R to swap between editor and terminal as needed. I haven't found a way to maximize the terminal, and swap easily between terminal and editor. I know I can make the terminal take up most of the screen, but a) this still leaves about 2 lines of editor open at the top, and b) there doesn't seem to be an easy way to then maximize the editor. Is there a way to minic the ISE behaviour that I haven't found yet?
To toggle between a full screen editor and a nearly full screen terminal you can use:
{
"key": "ctrl+alt+m",
"command": "workbench.action.toggleMaximizedPanel"
}
with your keybinding of choice to replace the Ctrl-Alt-m : that is mine. You just need to "maximize" the terminal first - pull it up as far as it goes. It will remember that between sessions.
Revisiting this :
As of v1.38 this is now pretty simple. There are two commands that will toggle the panel/editors to full screen.
Pick some keybinding to use for the toggle trigger:
{
"key": "ctrl+alt+q",
"command": "workbench.action.toggleMaximizedPanel",
// "command": "workbench.action.toggleEditorVisibility" either one
"when": "!terminalFocus"
},
The above will expand the panel or editor to full height, but toggling back will return the panel to its original size but not to nothing. If you want the terminal to bounce between full open and full closed try both of these keybindings:
{
"key": "ctrl+alt+t", // you could use "key": "ctrl+`", if you wish
"command": "workbench.action.closePanel",
// "when": "terminalFocus"
},
{
"key": "ctrl+alt+t",
"command": "workbench.action.toggleMaximizedPanel",
"when": "!terminalFocus"
},
The order of the above 2 keybindings is important.
v1.50 is adding the setting panel.opensMaximized - I tried its different options but couldn't get a simpler result than the two keybindings ctrl+alt+t version I showed above. In any case, start with the panel closed for it to work well.
The below outlines my solution after reading #Mark 's answer, as it's slightly different. I use ctrl-alt-m to switch between a full-sized terminal and full-sized editor.
note: this includes the mentioned integrated terminal and vscode application menu bars.
For posterity's sake, I'm on vscode version 1.40.1.
Implementation
You'll need to add to your keybindings within vscode and execute a manual step.
keybindings.json
Add this to your keybindings.json file, accessible via the Keyboard Shortcuts editor:
{
"key": "ctrl+alt+m",
"command": "workbench.action.toggleMaximizedPanel",
"when": "!terminalFocus"
},
{
"key": "ctrl+`",
"command": "-workbench.action.terminal.toggleTerminal",
"when": "!terminalFocus"
},
{
"key": "ctrl+alt+m",
"command": "workbench.action.terminal.toggleTerminal",
"when": "terminalFocus"
}
Slide down the integrated terminal
Once you've done this and saved your keybindings.json file you need to manually slide down the integrated terminal all the way off the screen on the bottom, after opening from your editor with ctrl+`.
Afterwards, you should be able to use ctrl+alt+m in your editor and your terminal to get a full-screen-ish experience moving between them.
I've tested this on Ubuntu and Fedora locally as hosts and using remote-ssh to an Ubuntu remote from a Windows 10 host. This has the added benefit of allowing you to get the by-default smaller terminal from within your editor using ctrl+` but use a single command, ctrl+alt+m, for switching between editor/terminal. YMMV!
Solution 1: Create Terminal in new Tab and Switch Between Tabs
Ctrl+Shift+P > Terminal: Create New Terminal in Editor Area create a terminal as a new Tab (A.k.a. Editor). It looks like:
Now you can toggle between Tabs (A.k.a. Editors) and Terminal (Which is in a new Tab) using View: Quick Open Previous Recently Used Editor in Group
Solution 2: Create Terminal in new Editor Group and Switch Between Editor Groups
Ctrl+Shift+P > Terminal: Create New Terminal in Editor Area to the Side create a terminal in new Editor Groups. It looks like:
Now you can toggle between window and terminal using View: Navigate Between Editor Groups
NOTE:
You can add keybinding to the commands as per your convenience. For example, in case of Solution 1:
{
"key": "ctrl+`",
"command": "workbench.action.createTerminalEditor"
},
{
"key": "ctrl+tab",
"command": "workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup",
"when": "!activeEditorGroupEmpty"
},
{
"key": "ctrl+w",
"command": "workbench.action.terminal.killEditor",
"when": "terminalEditorFocus && terminalFocus && terminalHasBeenCreated && resourceScheme == 'vscode-terminal' || terminalEditorFocus && terminalFocus && terminalProcessSupported && resourceScheme == 'vscode-terminal'"
}
Here, Ctrl+W & Ctrl+Tab are set by default. I just modified Ctrl+`.
The above keybinding will
Create terminal when you press Ctrl+`
Close terminal when you press Ctrl+W
Toggle between fullscreen editor and terminal when you press Ctrl+Tab
Opening the terminal in VS Code in full screen
This solution will replace the standard keybindings in VS Code so the terminal toggles in full screen.
Implementation
Open command palette ctrl+shift+p and search for Preferences: Open Keyboard Shortcuts (JSON) and paste this between the square brackets.
{ "key":"ctrl+j", "command":"workbench.action.toggleMaximizedPanel","when":"!terminalFocus" },
{ "key": "ctrl+oem_3", "command":"workbench.action.toggleMaximizedPanel", "when":"!terminalFocus" }
There is now an extension for exactly this. It is the "maximizeterminal" extension by Samuel T Scott. It redefines ctrl+` for opening terminal full-screen. The above keybinding methods, are also great, but in my experience they tend to not work properly once you start opening files by using cli like "code app.js". While using the extension such problems do not occur.
For macOS users, you can set the shortcut in the same keybindings.json file.
You can access the file using the shortcut cmd+shift+p, then write/select Preferences: Open Keyboard Shortcuts (JSON).
In keybindings.json, paste the following code between the square brackets:
{ "key": "cmd+alt+m",
"command": "workbench.action.toggleMaximizedPanel",
"when": "!terminalFocus" }
You can change the shortcut to whatever suits you (mind rewriting any of the default ones!), but I set mine to the same as others suggested (cmd+option+m) to keep a "standard".
Right click on the terminal instance name at the top as seen below and then select "move terminal into editor area". This will allow you to have a full workspace view within VS Code.
Image of process
I love this question, I believe I figured out something or at least got the behavior I was looking for.
Using the workspace setting here: https://github.com/microsoft/vscode/issues/107624
(enter ctrl+, and search "openmaximized" and set the dropdown to "always")
From there I set the keyboard shortcut for "Toggle Terminal" to ctrl+j (or whatever you may prefer) and now when I toggle my terminal it goes from full screen to toggled off
For MacOS I found useful cmd+option+m