This question already has an answer here:
How do I get all the tabs in a Visual Studio Code window as an array of filenames?
(1 answer)
Closed 8 months ago.
I wanna get all the opened files with vscode api.
for example, my editor opened 001.cpp and 002.cpp, i wanna get a array like this, [0] = "001.cpp", [1] = "002.cpp".
I tried to find such api on https://code.visualstudio.com/api/references/vscode-api#TextEditor. But i only find TextEditor, and it only returned the focused file.
vscode.window.activeTextEditor.document.fileName
But i wanna an array including all the opened filename.
Since of April 2022 (1.67) you can now use Tab API to achieve that.
So, in your case you need this:
import * as vscode from 'vscode'
// Get labels of opened files in all groups
vscode.window.tabGroups.all.flatMap(({ tabs }) => tabs.map(tab => tab.label))
Related
This question already has answers here:
Dash line between curly brackets in VS Code
(3 answers)
Closed 10 days ago.
When I worked in visual studio code on linux, there was such a strip from one curly brace to another. I do not know what was responsible for its display, maybe some kind of extension. But after switching to Windows, I don't see them anymore, although I seem to have installed the same extensions. I do not know what it is called and how to return it, maybe someone knows?
This is the editor.guides.bracketPairs setting. The default value is false when it's not specified, so you must have set it to true in your user settings.json file or in your workspace .vscode/settings.json file. Find out where you set it and either set it to false or remove that line to get false as the default value.
I am currently trying to make an extension in visual studio that uses the results from the normal search and shows the results in it's own view that does not display the found results per file, but per user-defined modules.
For example the usual search gives:
4 results found in 3 files
src/extension.ts (2 results)
folder2/file1.ts (1 result)
folder2/file2.ts (1 result)
Then my extension could show:
4 results found in 2 modules
src/ (2 results)
folder2/ (2 results)
For this I looked up the Contribution points and in "contributes.menus" there is the Explorer context menu that contains the group "4_search" - Commands related to searching in the search view.
How can I use this contribution point for my extension? Is it even feasible to use the search results and show the data in a new view like the example above?
Edit:
I realised that I did not understand the contribution points at all when asking and it is not what I need. Do you know how I can execute a command whenever the user searches for something in the search view and get the search results as parameters for the command?
Thanks for your help.
This question already has answers here:
Select multiple lines with cursors at each line start
(5 answers)
Closed 4 years ago.
How to find all occurrences of word or a character and select them once and edit using multi cursor in visual studio code?
I have list of users and need to add domain before names.
I have:
abc
pqr
xyz
I want :
domain\abc
domain\pqr
domain\xyz
I want to search for a new line character which will take me to the end of the each user name then by pressing home button I should reach to the beginning of each user where I will type "domain\" and it will modify each user at once.
I was able to do this in sublime text 3 by find all feature which provides multi cursor at each occurrence of character.
Is there any way to do the same in VS code ?
The easiest way to achieve this doesn't involve searching for newlines but rather by
Making a selection (Such as Ctrl+A)
Add cursor to all lines of the selection (Alt+Shift+I)
Pressing home (Home)
You can use search and replace with a simple regular expression.
Search for: ^(.+)$
Replace with: domain\\$1
Make sure to enable regular expressions (Alt+R).
This question already has answers here:
Automatically hard wrap lines at column in VSCode
(11 answers)
Closed 3 years ago.
In Visual Studio Code, when you press ALT SHIFT F to format HTML document, VS Code would wrap a line that is too long into multiple lines.
I think VS Code let the line grow too long before wrapping. Is there a setting in VS Code to tell it to wrap after certain line length?
This question is NOT a duplicate of the hard wrap question. This is about wrapping during format document process.
Open user settings: File - Preferences - Settings
Then add/edit this item:
"html.format.wrapLineLength": 80
FYI the new settings are in effect after you save the changes.
If you are formatting HTML and are annoyed that VScode formats your long lines into multiple lines, go to:
File > Preferences > Settings
Search for:
HTML › Format: Wrap Line Length
and set it to 0
This question already has answers here:
Visual Studio Code formatting for "{ }"
(6 answers)
Closed 2 years ago.
I am using Visual Studio Code with the C/C++ extension.
The command Ctrl+Shift+I formats the code with opening brace on a new line like this:
int f ()
{
return 0;
}
What I want is this:
int f() {
}
Is there any setting you can change to do this? If not, is there any other extension that would format the code how I want?
Vscode ships with a version of the clang-format extension. As it is described in the vscode docs you can add a .clang-format file to your workspace root that specifies style rules. How the .clang-format file is formatted and which rules exist can be read here.
Instead (or in addition) you can use an existing style and just configure a few options. For that you either configure the BasedOnStyle property in your .clang-format file or you can set the "C_Cpp.clang_format_style" option in your vscode user settings.
In your case, to achieve the opening curly bracket on the same line, you can just use the Google's C++ Style. To enable it via the vscode settings, add the following entry to your user settings:
"C_Cpp.clang_format_style": "Google"