Apply one or more commands to all files in the Workspace.
If you want to apply multiple commands or a command with arguments you need to use the extension multi-command by ryuta46.
This extension is based on the Format All Files in Workspace by Alex Ross
The extension exports the following command:
commandOnAllFiles.applyOnWorkspace
commandOnAllFiles.commands
.The command will:
This means that files that are open in a tab will be closed if they meet the criteria. If there is a way to get a list of files currently open this will change.
commandOnAllFiles.includeFileExtensions
: Only files with file extensions in this list will be processed..
(period). Example [".html", ".css", ".js"]
[]
.commandOnAllFiles.includeFiles
: List of regular expressions of file paths to include. Overrides includeFileExtensions. (default: undefined
)regex
: string with a regular expression that is searched in the file path (separator /
)/workspace_name/relative_file_path
flags
: flags to use with the property regex
(only i
makes sence) (default ""
)commandOnAllFiles.excludeFolders
: These folders will be skipped when looking for files to process.["node_modules", "out", ".vscode-test", "media", ".git"]
commandOnAllFiles.includeFolders
: An array of Glob Patterns describing folders that will determine which files will be processed.**
at the start of the Glob Pattern.commandOnAllFiles.saveFiles
: If true
save and close a modified file. If false
keep a modified file open in the editor. (default: true
)commandOnAllFiles.commands
: An object with key/value items describing the commands to use.includeFileExtensions
, excludeFolders
and includeFolders
. The properties of the value object are:
command
: the commandID to applyincludeFileExtensions
: override commandOnAllFiles.includeFileExtensions
if definedincludeFiles
: override commandOnAllFiles.includeFiles
if definedexcludeFolders
: override commandOnAllFiles.excludeFolders
if definedincludeFolders
: override commandOnAllFiles.includeFolders
if definedsaveFiles
: override commandOnAllFiles.saveFiles
if definedlabel
, description
, detail
: when applyOnWorkspace
is called from the command palette it shows a QuickPick list. These 3 properties (strings
) are used in the construction of the QuickPickItem. The default value for label
is the key name of the command. In the 3 properties you can use icons with the $(<name>)
-syntax.No matter what the value of commandOnAllFiles.excludeFolders
is the ".git"
entry will always be added. This to prevent that if you make a mistake in the configuration you could corrupt your Source Control Repository.
To prevent an incorrect directory match in the includeFolders
glob patterns always include the separator /
. Using ["/src/"]
prevents a match on directory src-test
.
If you know the command description from the View > Command Palette (Ctrl+Shift+P
), what do you need to set the "command"
property.
For example you want to apply the command Inline CSS
, you have to find the command ID for this command with the Keyboard Shortcuts editor.
Inline
Inline CSS
command"command"
propertyAn example of how to configure the extension to add Hello
to the end of all .txt
files in the Workspace. We need the extension multi-command because the have to perform a sequence of commands.
The default value for commandOnAllFiles.excludeFolders
is enough for this example.
In settings.json
:
"multiCommand.commands": [
{
"command": "multiCommand.addHelloAtEnd",
"sequence": [
"cursorBottom",
{ "command": "type",
"args": { "text": "Hello" }
}
]
}
],
"commandOnAllFiles.commands": {
"Add Hello to the End": {
"command": "multiCommand.addHelloAtEnd",
"includeFileExtensions": [".txt"]
}
}
In keybindings.json
:
{
"key": "ctrl+i a", // or any other key combo
"command": "commandOnAllFiles.applyOnWorkspace",
"args": ["Add Hello to the End"]
}
If you want to limit the files included with a regular expression you need to use the includeFiles
property:
In settings.json
:
"commandOnAllFiles.commands": {
"Add Hello to the End": {
"command": "multiCommand.addHelloAtEnd",
"includeFiles": [
{ "regex": "/test/test-server.*\\.py" },
{ "regex": "/test/test-game.*\\.py" }
]
}
}