I am using the extension clang-format in vscode to format my c and cpp files. Followed by the instructions on the internet, i set the setting file like below, but i can't figure out how to change the default indent width.
"terminal.integrated.defaultProfile.linux": "bash",
"clang-format.style": "Google",
"clang-format.language.c.enable": true,
"clang-format.language.cpp.enable": true,
"clang-format.executable": "/usr/bin/clang-format-12",
"[c]": {
"editor.defaultFormatter": "xaver.clang-format",
"editor.wordBasedSuggestions": false,
"editor.suggest.insertMode": "replace",
"editor.semanticHighlighting.enabled": true,
},
"[cpp]": {
"editor.defaultFormatter": "xaver.clang-format"
}
}
"clang-format.style": "{ BasedOnStyle: Google, IndentWidth: 4}"
All extension options are described here vscode-clang-format-provider/package.json.
All clang-format style options are described here Clang-Format Style Options.
Related
I need to apologize in advance because I am totally confused at the moment. I've been wrangling with my .eslintrc.json (at the end of my post) for several hours now.
All I want, is to set single quotes. To my understanding single quotes are part of the default settings of "eslint:recommended". But when I execute Prettier, double quotes are being set.
Next thing I tried was setting single quotes in rules for "prettier/prettier". That's not working either. Prettier is still setting double quotes.
Last of my options was setting single quotes directly in rules as "quotes: ["error": "single"].
Strangely enough though, double quotes are being shown as linting errors while editing.
I am running out of options.
Maybe someone can help me.
Here's my .eslintrc.json:
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true,
"node": true
},
"extends": ["eslint:recommended", "prettier"],
"plugins": ["prettier", "#babel", "vue"],
"parserOptions": {
"ecmaVersion": 2022,
"parser": "#babel/eslint-parser",
"sourceType": "module"
},
"rules": {
"no-console": "off",
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"prettier/prettier": [
"error",
{
"singleQuote": true,
"onlyUseLocalVersion": false
}
]
}
}
Finally I tried to set
{
"prettier.singleQuote":true
}
in coc-settings.json (:CocConfig) and now it works.
That shouldn't be necessary if singleQuote is already set in .eslintrc. So I consider setting singelQuote in coc-settings.json rather a workaround than a real solution.
I am trying to format a js file with prettier but it seems prettier is breaking the code syntax. I want to achieve this
(expectated result) but the red lines appear. On save I get the following result. While running the code I get the following error TypeError: {} is not a function (error image). I tried the following but none seems to work in my case.
Why do I keep getting Delete 'cr' [prettier/prettier]?
Visual Studio Code [eslint] Delete 'CR' [prettier/prettier] on windows
I am using the following .prettierrc.js
module.exports = {
tabWidth: 2,
bracketSpacing: true,
endOfLine: "auto",
jsxBracketSameLine: true,
printWidth: 100,
semi: false,
singleQuote: false,
trailingComma: "none"
}
In my .eslintrc.json file I have the following rules set for prettier
"prettier/prettier": [
"error",
{
"bracketSpacing": true,
"endOfLine": "auto",
"jsxBracketSameLine": true,
"printWidth": 100,
"semi": false,
"singleQuote": false,
"trailingComma": "none"
}
],
I have tried changing LF to CRLF and vice versa that appears in the bottom section of vscode but no success. What else am I missing?
I found out that installing Django 1.0.2 extention on VS code disables the default html.autoClosingTags, meaning that, even if this is set to True, it won't autoclose HTML tags.
Does anyone knows how to fix it?
Or at least another extention highlighting django syntax that does not disable html.autoClosingTags.
UPDATE:
As suggested by #Nadim Al Abdou
In my settings.json (File>Preferences>Settings> settings.json) there was:
{
"python.pythonPath": "C:\\Applicazioni_Tommaso\\Anaconda3\\pythonw.exe",
"workbench.startupEditor": "newUntitledFile",
"workbench.colorTheme": "Atom One Dark",
"workbench.tree.indent": 30,
"terminal.integrated.cwd": "C:\\users\\tommaso",
"window.zoomLevel": 0,
"workbench.editor.enablePreview": false,
},
I turn it into:
{
"python.pythonPath": "C:\\Applicazioni_Tommaso\\Anaconda3\\pythonw.exe",
"workbench.startupEditor": "newUntitledFile",
"workbench.colorTheme": "Atom One Dark",
"workbench.tree.indent": 30,
"terminal.integrated.cwd": "C:\\users\\tommaso",
"window.zoomLevel": 0,
"workbench.editor.enablePreview": false,
"files.associations": {
"**/*.html": "html",
"**/templates/**/*.html": "django-html",
"**/templates/**/*": "django-txt",
"**/requirements{/**,*}.{txt,in}": "pip-requirements"
},
"emmet.includeLanguages": {"django-html": "html"},
},
close and re-open vs code, but it does not work.
Update:
This does not work because I am editing the User settings
press ctrl+p
insert >open settings in the search bar
select preferences: Open User Settings (JSON)
while it is now clear that I should edit the Default settings
press ctrl+p
insert >open settings in the search bar
select preferences: Open Default Settings (JSON)
where I actually found the "files.associations": { line.
The problem is I cannot edit the file, beacuse as I try to, vscode shows the message: "cannot edit in read only editor".
What can I do to insert the line "emmet.includeLanguages": {"django-html": "html"}, ?
you need to edit your global settings.json file like so
1.
"files.associations": {
"**/*.html": "html",
"**/templates/**/*.html": "django-html",
"**/templates/**/*": "django-txt",
"**/requirements{/**,*}.{txt,in}": "pip-requirements"
},
2.
"emmet.includeLanguages": {"django-html": "html"},
I created this extension in one day, I'm adding more features, I saw you are adding:
"emmet.includeLanguages": { "django-html" : "html" }
I tried adding it and is working for me. To be honest I'm not sure Why this is not working for you, Did you resolve it?
Can you try updating VSCode please? This info is helpful for me.
Another way is moving up the line, exactly before:
"files.associations": {
Thanks,
Roberth.
I try to create a simple regex-find and replace task in Visual Studio Code.
Currently I copy from the AD some Users to a temporary file in Visual Studio code and remove the "CN=" at the beginning of the line and all the aditional informations after the first "," (regex: ,.*$). This works fine with Find&Replace in VSCode but I have manually to type it in every time I want to remove this.
So the question is, is it possible to automate this kind of task? I know there are some external tools (https://code.visualstudio.com/docs/editor/tasks) but I'm struggling to get it working...
Edit: Example requested (my regex is working, that's not the problem:/. I need an example how to automate this task... )
EXAMPLE
CN=Test User,OU=Benutzer,OU=TEST1,OU=Vert,OU=ES1,OU=HEADQUARTERS,DC=esg,DC=corp
Expected Output
Test User
This extension does the job:
https://marketplace.visualstudio.com/items?itemName=joekon.ssmacro#overview
It seems like the regex adheres to:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
Example
Create a file regex.json:
[{
"command": "ssmacro.replace",
"args": {
"info": "strip out EOL whitespace",
"find": "\\s+$",
"replace": "",
"all": true,
"reg": true,
"flag": "gm"
}
}]
"info" is just a reminder, doesn't do anything.
Set a shortcut in keybindings.json:
"key": "ctrl+9",
"command": "ssmacro.macro", "args": {"path": "C:\\...\\regex.json"}
You can batch multiple commands together [{...},{...}] which is useful for applying a whole set of regex operations in one go.
As of today, it seems it's still not possible without an extension. Here are 2 other extensions than the one proposed in the accepted answer (both are also open-source):
● Batch Replacer (but it doesn't work on the documents open in the editor : "you must have a folder open for editing and all files in it will be updated."*)
● Replace Rules: you simply add some rules in your settings.json (open the palette with F1 or ctrl+shift+p and select Preferences: open settings (JSON)).
"replacerules.rules": {
"Remove trailing and leading whitespace": {
"find": "^\\s*(.*)\\s*$",
"replace": "$1"
},
"Remove blank lines": {
"find": "^\\n",
"replace": "",
"languages": [
"typescript"
]
}
}
Extensions folder is : %USERPROFILE%\.vscode\extensions
And here is an extension I wrote that allows you to save find/replaces in a file or searches across files as a named command and/or as a keybinding: Find and Transform. Using the OP's original question, make this setting (in settings.json):
"findInCurrentFile": { // in settings.json
"reduceUserEntry": {
"title": "Reduce User to ...", // will appear in the Command Palette
"find": "CN=([^,]+).*",
"replace": "$1",
"isRegex": true,
// "restrictFind": "selections", // default is entire document
}
},
You could also make that for searches across files with this setting:
"runInSearchPanel": {
"reduceUserEntry": {
"title": "Reduce User to ...", // will appear in the Command Palette
"find": "CN=([^,]+).*",
"replace": "$1",
"isRegex": true
// "filesToInclude": "${fileDirname}"
// "onlyOpenEditors": true
// and more options
}
}
As a standalone keybinding:
{
"key": "alt+r", // whatever keybinding you want
"command": "findInCurrentFile", // or runInSearchPanel
"args": {
"find": "CN=([^,]+).*",
"replace": "$1",
"isRegex": true
The extension can also run multiple finds/replaces - just put them into an array:
"find": ["<some find term 1>", "<some find term 2>", etc.
and the same with replacements, make an array of them.
I find the auto match behavior in sublime text 3 is not quite up to snuff when you're typing code and more importantly when you're going back to edit in real time it can add all kinds of parens or quotes you don't really need.
But it's pretty much always perfect at auto matching squirly brackets {} so that's still a very useful feature especially since I type a lot of them in a local markup language.
I know I can turn auto match off but I don't want to turn off the behavior entirely, just modify it to not auto match "" or ().
Does anyone know the command to put in the user settings for this?
Here's the steps I've done to try to resolve this:
find ~/ -name "Sublime Text"
find ~/ -name "BracketHighlighter"
Both return nothing. So I can't find this 'BracketHighlighter.sublime-settings'
Instead of looking for it on the hard drive, I accessed it via the built in menus in Sublime Text via:
Preferences ->
Package Settings ->
Bracket Highlighter ->
Bracket Settings - User
This last menu option opens a file called "~/.config/sublime-text-3/Packages/User/bh_core.sublime-settings. In there I've pasted the code from AGS' answer and toggled:
"auto_match_enabled" : true,
"auto_match_enabled" : false,
I have tried both auto match settings while the code has been saved to the bh_core.sublime-settings file. Neither option produces the result as expected. With auto match on, braces, brackets, and quotes are matched. With auto match off, nothing is matched. But I have confirmed the module is on and active as brackets are getting highlighted when selected.
I know I can turn auto match off but I don't want to turn off the behavior entirely, just modify it to not auto match "" or ()
You could install and customize the settings of the BracketHighlighter package.
Disable the system auto-matching:
~/Library/Application Support/Sublime Text 2/Packages/User/Preferences.sublime-settings
"auto_match_enabled": true,
Then edit:
OS X file location:
~/Library/Application Support/Sublime Text 2/Packages/User/BracketHighlighter.sublime-settings
{
"name": "round",
"open": "(\\()",
"close": "(\\))",
"style": "round",
"scope_exclude_exceptions": ["string.other.math.block.environment.latex"],
"scope_exclude": ["string", "comment"],
"language_filter": "blacklist",
"language_list": ["Plain text"],
"find_in_sub_search": "true",
"ignore_string_escape": true,
"enabled": true
},
{
"name": "double_quote",
"open": "(\")",
"close": "(\")",
"style": "double_quote",
"scopes": ["string"],
"language_filter": "blacklist",
"language_list": ["Plain text"],
"sub_bracket_search": "true",
"enabled": true
},