I'm using the VSCodeVim extension and am trying to configure some shortcuts for normal mode without the need of turning the extension off then on again via its togglevim command. I'm trying to add the "View: Close Editor", "View: Open Previous Editor", and "View: Open Next Editor" commands as they're named in the keyboard shortcuts menu to the "vim.normalModeKeyBindings" setting but don't know what to put for the "commands" value.
The commands towards the bottom of the shotrcuts menu are listed in their name form while most of the commands above them have a "cleaned up" name that displays in the F1 command palette and doesn't seem to correspond to the underlying command name.
I've tried the following which results in a command not found notification:
"vim.normalModeKeyBindings": [
{
"before": [ "<C-w>" ],
"commands": [
"view.closeEditor" // I've tried all kinds of variations of capital/lowercase letters and periods/hyphens.
]
},
{
"before": [ "<C-pageup>" ],
"commands": [
"view.openPreviousEditor" // See above.
]
},
{
"before": [ "<C-pagedown>" ],
"commands": [
"view.openNextEditor" // See above.
]
}
]
How do I find out what the underlying command name is for these "View" commands (or any such named command) so I can reference them in the settings.json?
Even though there is only a title for some commands, like View: Close Editor you can still right-click on that command title and choose
Copy Command ID
from the context menu. That'll give you the version you need, like
workbench.action.closeActiveEditor
I don't use vim so I hope you can adapt that to use as you need.
I often find myself working on file test-1a.robot and I want to open test-1b.robot, which is the next alphabetical file in the editor list.
With the files are open and I have a "sort tabs" extension enabled I can use ctrl+pgup and ctrl+pgdn which is already something, but I'd like to have it even without the tab sorting or opening files in advance.
Maybe you need to train yourself in the following key combo:
Ctrl+Shift+E DownArrow Enter
I tried to use multi-command to create a combo of
show explorer tab
go to next file down
open this file
For (1.) I could find a command, it sets the focus on the current file in the Explorer.
Edit With the tip from mark for the commands to type the cursor down (2) and select command (3) in listboxes.
You can add this to your settings and create a key binding for this new command
"multiCommand.commands": [
{
"command": "multiCommand.openNextABCFile",
"sequence": [
"workbench.view.explorer",
"list.focusDown",
"list.select"
]
}
]
It opens the next alphabetical filename in preview mode.
VSCode remembers the file tabs that are open in my Workspace from the last environment, and so if I close VSCode and re-open, I have the same files opened.
Over a day or two of work, I may switch between 2 or 3 different feature branches while my PR's are going through review.
Each feature branch is usually on a totally different area of the code base, which means, I will want to open different groups of files when working on each branch.
I wonder if there is a way to save snapshots of open tabs so that I can re-reopen in future.
A really nice flow would be to have those files open automatically whilst other files close when VSCode detects a branch change.
Get a "snapshot" of currently opened files.
Save this snapshot somewhere; make it easy to change.
Use the snapshot to open all of its files; close all other files first.
Be able to make multiple snapshots and call each one easily.
(1) is harder than you might think. There are a number of vscode issues about searching only within the currently opened files and the problem remains largely unsolved after a few years for this reason.
Demo: get the relative paths of all opened files (unfortunately the gif creation software did a poor job of capturing all the keystrokes used in all these demos) :
Holy crap, what just happened. One keybinding and they are collected and formatted in a specific way.
A number of things happened. The only way I know of to efficiently get a list of opened files (maybe true even in an extension) is through the "Open Editors" view. So we
(a) focus that Open Editors view,
(b) select the entire list, and fortunately there is a
(c) copyRelativeFilePath command (or copyPath for the full path) that will get them all in a list.
But the list initially looks like:
1.html
simple\\gulpfile.js
test1.txt
which isn't going to do us much good. But it is now on the ClipBoard and there is an extension, Replace Rules that is able to run the Clipboard content through a series of regex's (without modifying the Clipboard content either) and paste the result somewhere. So you will need that extension and a macro extension, here using multi-command to run all the steps. Here is the macro which goes into your settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.getOpenedEditorsForTaskOpenAll",
"interval": 50,
"sequence": [
"workbench.files.action.focusOpenEditorsView",
"list.selectAll",
"copyRelativeFilePath",
// "copyFilePath",
"workbench.action.focusActiveEditorGroup",
{
"command": "replacerules.pasteAndReplace",
"args": {
"ruleName": "Prepare file list for task open"
}
},
"editor.action.formatSelection",
"cancelSelection",
"deleteLeft"
]
}
]
Here is the replacerules rule that is used in the macro:
"replacerules.rules": {
"Prepare file list for task open": {
"find": ["(\\\\)", "^(.+)$"],
"replace": ["\\\\", "\"'$1'\","]
}
}
It just modifies that bare file list into something we can use in a task. Here is a keybinding to run that macro (keybindings.json):
{
"key": "ctrl+shift+i",
"command": "extension.multiCommand.execute",
"args": {
"command": "multiCommand.getOpenedEditorsForTaskOpenAll"
},
}
You should be able to test this already to see if it'll dump the formatted file list to wherever your cursor is in the current text editor.
One way to open up all these files at once is to put them into a task (in tasks.json):
{
"label": "Open snapshot 1",
"command": "code",
"args": [
],
"type": "shell",
"problemMatcher": [],
"dependsOrder": "sequence",
"dependsOn": [ "close all editors" ]
},
{
"label": "close all editors",
"command": "${command:workbench.action.closeAllEditors}",
"type": "shell",
"problemMatcher": []
},
You see the task Open snapshot 1 is dependent on the close all editors task so that happens first. In the Open snapshot 1 the command is code to open all the arg files. Put your cursor in the args array and that is where the properly formatted list of files to open will be written by the macro. Demo:
If you want to update that file list you can just select them and rerun the macro. And you can now set up as many Open snapshot <n> tasks as you want (with whatever labels you want to give them).
Now, to trigger the task we will use a keybinding as well:
{
"key": "alt+s 1",
"command": "workbench.action.tasks.runTask",
"args": "Open snapshot 1"
},
{
"key": "alt+s 2",
"command": "workbench.action.tasks.runTask",
"args": "Open snapshot 2"
},
etc. As noted earlier, running this task will first run the dependent task which closes all currently opened files. If you just wanted to open a batch of files you frequently use without closing the others, just remove the "dependsOn": [ "close all editors" ] option.
Here is a final demo of the task closing the open files and opening the snapshot files (I just changed the file list above a little to make it look different).
Two things to remember:
(1) the Editor > Open Editors: Visible setting must be enable with a number high enough to show all your opened files. The Open Editors can be hidden so you don't have to look at it all the time if you don't want, but it will be opened automatically by the macro - that can't be avoided. You can see it opening in the demos. It can be hidden by its context menu.
(2) The terminal is used, so you see it opening.
It seems like a lot of set-up but the operation is actually pretty simple - just a couple of keybindings to remember.
Try an extension called File Group.
My searching reveled that a lot of people are looking for this option but vsCode does not seem to have any good way to do it. This extension lets you list out the files with full path and associate them to a key shortcut.
Three files below will load by hitting ctrl-alt-1 if you add this to youProject.code-workspace:
"1": {
"files": [
"C:\\temp\\file1.txt",
"C:\\svn\\foo.txt",
"C:\inetpub\wwwroot\iisstart.htm"
]
}
(It is a pain to set up if you are new to vsCode, hopefully it gets developed further.)
This worked for me. But it may have side affects when git does refresh
https://marketplace.visualstudio.com/items?itemName=gkotas.restore-git-branch-tabs
It seems that there is an extension that does the job: Editor Group Minimizer
There's this extension, that seems to kind of work:
Save and Restore Tabs
It seems to get most of the files and maintains the file split, but if I have multiple tabs on multiple groups, sometimes the secondary ones aren't opened.
There's an extension that would save your open tabs and swap them based on your git branch. Seems very useful, but in practice it was a little too intrusive.
Looks like its been abandoned, but there's this fork: Restore Git Branch Tabs Improved Tried it but isn't worked like I remember but maybe I just missed something for setup.
In Sublime I have a keybinding set up like so:
{ "keys": ["super+j"], "command": "next_view_in_stack" },
I am trying to recreate this behavior in VSCode with
{
"key":"cmd+j",
"command":"workbench.action.previousEditor"
},
but instead of going to my previous tab, it goes one tab to the left. Is there any concept of a "stack" of editors like in Sublime?
You need to configure two different key bindings to get this working correctly.
First configure workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup to Cmd + J, and set its when expression to !inQuickOpen.
Also, to allow using the shortcut repeatedly once the quick open list is already open, you need to also configure workbench.action.quickOpenNavigateNext to Cmd + J, and set its when expression to inQuickOpen.
For me this worked when I wanted to configure Alt + Tab for the recent file cycling shortcut. Hope this helps.
There are the following commands that may give you the functionality you're looking for:
{ "key": "ctrl+tab", "command": "workbench.action.openNextRecentlyUsedEditorInGroup" },
{ "key": "ctrl+shift+tab", "command": "workbench.action.openPreviousRecentlyUsedEditorInGroup" },
use
'alt + leftArrow' & 'alt + rightArrow" // switch between recent stack tabs
Hi i want to comment all console.logs in all files in a particular folder
heres what i have done
[{
"args": null,
"command": "copy"
}, {
"args": {
"extend": false,
"to": "bol"
},
"command": "move_to"
}, {
"args": {
"characters": "//"
},
"command": "insert"
}]
it will comment current line but i dont know how to search console.log in all files macro dont save find/replace before deploying web on production server
Updated:
actually when in production i want all console.log to be commented and when in dev all console.log to be uncommented, in all files. I have more than 40 pages. I cant do it manually. Is there any plugin or macro for that?
Open File -> Search, and enter console.log in the search field. Press Find All to select all the instances in the current file. Then hit Ctrl/ (Windows or Linux) or ⌘/ (OS X) to comment out all those lines.
Unfortunately, this only works for one file at a time. Macros can't handle multiple files or views, you'd need a plugin for that. If you have an absolute ton of files to change that can't be done by hand, let me know and I'll see what I can whip up.