vs code

# a paper about how to increase the performance

https://betterprogramming.pub/5-tips-to-boost-the-performance-of-your-vs-code-editor-ff28dda68d9b

 

#backup installed extentions

The simplest way is to install the extention VScode Backup

step 1: know which extentions are installed by code --list-extensions

austin.code-gnu-global
CoenraadS.bracket-pair-colorizer-2
cschlosser.doxdocgen
hbenl.vscode-test-explorer
jeff-hykin.better-cpp-syntax
marus25.cortex-debug
matepek.vscode-catch2-test-adapter
ms-python.python
ms-python.vscode-pylance
ms-vscode.cpptools
ms-vscode.test-adapter-converter
RedVanWorkshop.explorer-exclude-vscode-extension
ruiquelhas.vscode-uppercase
streetsidesoftware.code-spell-checker
xaver.clang-format

step 2: install in new environment

code --install-extension xxxx

step 3: configuration

cd /home/$USER/.config/Code/User
tar -czf code-config.tar.gz *.json
mv code-config.tar.gz /home/$USER/code-backup

#useful shortcut

 

Command Palette CTRL +SHIFT +P
Quick Open CTRL + O
Toggle sidebar CTRL + B
Copy line CTRL + C without select the line
Copy line SHIFT+ALT+UP or SHIFT+ALT+DOWN
Delete line CTRL + SHIFT + K
Select Line CTRL + L
multi-Select CTRL + D
Search in all files CTRL + SHIFT + F
Comment block SHIFT + ALT + A
Commont a line CTRL + /
Go back or move forward ALT + LEFT / RIGHT
Show all symbols CTRL + T
Move a line ALT + UP or Down

 

#using clang to format code

detail see https://www.dynamsoft.com/codepool/vscode-format-c-code-windows-linux.html

1. install clang format tool at llvm.org.

Actually, you don't need whole package, you only need the clang-format.exe.

2. install extention clang-format & configure

The example of configuration.

 

 The filename must be .clang-format. a method to make a file without filename. mv xx.clang-format .clang-format

 I would better put the .clang-format file at your project/workspace folder.

The .clang-format file can be generated by : clang-format.exe -style=llvm -dump-config > .clang-format

Note: brace at a new line 

BraceWrapping:
  AfterClass:      true
  AfterControlStatement: true
  AfterEnum:       true/false
  AfterFunction:   true
  AfterNamespace:  true/false
  AfterObjCDeclaration: true/false
  AfterStruct:     true/false
  AfterUnion:      true/false
  BeforeCatch:     true/false
  BeforeElse:      true/false
  IndentBraces:    true/false
BreakBeforeBraces: Custom

 

Useful links:

https://clang.llvm.org/docs/ClangFormatStyleOptions.html

 

#exclude folder

setting

 

 

#macro define

"configurations": [
{
   ...
   "defines":[
       "MYSYMBOL",
       "MYVALUE=1"
   ]
}
], ...

 

#editor ruler

  1. File -> Preferences -> Settings
  2. Select the tab option: Applies to only => 'User' or 'Workspace'
  3. Search for 'rulers'
  4. open the setting.json under 'rulers'
  5. add the line "editor.rulers": [80]

#debug a makefile project

 

launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [


        {
            "name": "Pusk", //I named it Pusk because i can 
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/Pusk", //path to your programs exe and exe name
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

task.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
      {
        "label": "Build",
        "type": "shell",
        "command": "make", //its like writing in console make //btw you can others commands like clean make build etc
        "group": {
          "kind": "build",
          "isDefault": true
        },
        "problemMatcher": {
          "owner": "cpp",
          "fileLocation": ["relative", "${workspaceFolder}"],
          "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
          }
        }
      }
    ]
  }

 

 

command palette: ctrl + shift + p 

go back to previous view : ctrl + alt + -

#my default font 

    "editor.fontSize": 20,
    "editor.fontFamily": "Consolas",
 
 
#other setting
{
    "workbench.colorTheme": "Quiet Light",
    "debug.onTaskErrors": "showErrors",
    "window.zoomLevel": -1,
    "[dart]": {
        "editor.formatOnSave": true,
        "editor.formatOnType": true,
        "editor.rulers": [
            80
        ],
        "editor.selectionHighlight": false,
        "editor.suggest.snippetsPreventQuickSuggestions": false,
        "editor.suggestSelection": "first",
        "editor.tabCompletion": "onlySnippets",
        "editor.wordBasedSuggestions": false
    },
    "editor.tabSize": 3,
    "workbench.startupEditor": "newUntitledFile",
    "editor.fontSize": 20,
    "editor.fontFamily": "Consolas",
    "cortex-debug.armToolchainPath": "C:/Program Files (x86)/GNU Arm Embedded Toolchain/9 2020-q2-update/bin/",
    "cortex-debug.JLinkGDBServerPath": "C:/Program Files (x86)/SEGGER/JLink_V614b/JLinkGDBServer.exe",
    "cmake.configureOnOpen": true,
    "workbench.colorCustomizations": {
        "terminal.background":"#F7F9FB",
        "terminal.foreground":"#405C79",
        "terminalCursor.background":"#405C79",
        "terminalCursor.foreground":"#405C79",
        "terminal.ansiBlack":"#F7F9FB",
        "terminal.ansiBlue":"#8B56BF",
        "terminal.ansiBrightBlack":"#AABCCE",
        "terminal.ansiBrightBlue":"#8B56BF",
        "terminal.ansiBrightCyan":"#568BBF",
        "terminal.ansiBrightGreen":"#56BF8B",
        "terminal.ansiBrightMagenta":"#BF568B",
        "terminal.ansiBrightRed":"#BF8B56",
        "terminal.ansiBrightWhite":"#0B1C2C",
        "terminal.ansiBrightYellow":"#8BBF56",
        "terminal.ansiCyan":"#568BBF",
        "terminal.ansiGreen":"#56BF8B",
        "terminal.ansiMagenta":"#BF568B",
        "terminal.ansiRed":"#BF8B56",
        "terminal.ansiWhite":"#405C79",
        "terminal.ansiYellow":"#8BBF56"
    }
 }

#Configuration files under .vscode folder

The code . command opens VS Code in the current working folder, which becomes your "workspace". As you go through the tutorial, you will create three files in a .vscode folder in the workspace:

  • tasks.json (compiler build settings)
  • launch.json (debugger settings)
  • c_cpp_properties.json (compiler path and IntelliSense settings)

#config the include path

ctrl+shift+p ->c++ edit configuration (UI) or c++ edit configuration (JSON), the includePath, add the linux driver include path

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/src/linux-headers-4.15.0-109-generic/include/"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

#go to the definition

alt + mouse click, open a new tab.

ctrl + alt + mouse click, open a seperated window

 

#exclude specific files or folders

on the workspace file->setting : file.exclude search.exclude. Example:

{
    "folders": [
        {
            "path": "."
        },
        {
            "path": "..\\esp-idf"
        }
    ],
    "settings": {
        "files.exclude": {
            "**/.git": true,
            "**/.svn": true,
            "**/.hg": true,
            "**/CVS": true,
            "**/.DS_Store": true
        }
        "search.exclude": {
            "**/node_modules": true,
            "**/bower_components": true,
            "**/github": true,
            "**/*.code-search": true,
            "**/examples": true,
            "**/docs": true
        }
    }
}

 

posted on 2020-04-13 17:02  荷树栋  阅读(298)  评论(0)    收藏  举报

导航