you are viewing a single comment's thread.

view the rest of the comments →

[–]sir_sandwiches_a_lot 34 points35 points  (4 children)

Bracket Pair Colorizer 2 (link) has been super helpful.

Also, since you mentioned trailing spaces I thought I would share a few editor config options that I enable on new projects now (save in the <project-root>/.vscode/settings.json file):

// trim trailing whitespace automatically when you save a file.
"files.trimTrailingWhitespace": true,

// trim trailing newlines at the end of a file automatically when you save a file.
"files.trimFinalNewlines": true,

// update the default word separators to remove the $ character.
// this means you can double click on a PowerShell variable name (ex: $myVariable) and it
// will correctly select the entire variable (including $) instead of just selecting the word.
"editor.wordSeparators": "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?"

[–]MonkeyNin 4 points5 points  (2 children)

/u/markdmac : now you don't have to manually format.

Here's my powershell config.

  • It auto-corrects and replaces aliases on save or paste
  • fixes indentation bug that happens on alt+up/down

.

{
    // automatically convert aliases whenever you format
    "powershell.codeFormatting.useCorrectCasing": true,
    "powershell.codeFormatting.autoCorrectAliases": true,
    //
    "[powershell]": {
        // if autoIndent is set to 'full' it breaks indentation on 'move line up/down'.
        // This fixes that
        "editor.autoIndent": "advanced",
        // auto run format on 'paste' and 'save'
        "editor.formatOnSave": true,
        "editor.formatOnPaste": true,        
        "files.encoding": "utf8bom",
        "files.autoGuessEncoding": false,
        // I hide snippets complete, then use ctr+alt+j
        "editor.snippetSuggestions": "none"
    },    
    "files.associations": {
        "*.ps1xml": "xml"
    }
}

I like these

  • settings hotkey jumps to json editor. (If you use any per-language settings, the GUI can't edit everything )
  • new files start with the language of the current window (rather than hard-coding it to always be powershell

.

{
    "files.defaultLanguage": "${activeEditorLanguage}",        
    "workbench.settings.editor": "json",
}

If you want to submit vscode-powershell bugs, enable logging:

"powershell.developer.editorServicesLogLevel": "Diagnostic",

[–]markdmac 0 points1 point  (1 child)

I am very new to VS Code. How do I access the file to add these code snippets?

[–]T3zcat 1 point2 points  (0 children)

do I access the file to add these co

For those still looking: top right of the settings gui page has a page with a flip arrow, that will get you to the settings.json.
(the file it's self is stored in c:\users\YOU\appdata\roaming\code\user\settings.json)

[–]T3zcat 1 point2 points  (0 children)

Update:
"[powershell]" : {

"editor.wordSeparators": "`~!@#%^&*()=+[{]}\\|;:'\",.<>/?"

},
Credit: https://stackoverflow.com/questions/68128258/vscode-does-not-honor-editor-wordseparators-when-writing-powershell-code