Ubuntu vscode detailed installation and cmake configuration, git push and pull, shortcuts


Ubuntu vscode installation and cmake configuration detailed operations

Install vscode

https://blog.csdn.net/zhaomengszu/article/details/112261258

Solution to the slow or failed download of VSCode official website_vscode cannot be downloaded_Who knows this kid’s blog-CSDN blog

1. The official website may fail to download due to network problems. You can use the above method to download

2. First go to the official website to find the compressed package you need to download

https://code.visualstudio.com/

3. If the network speed is too slow and the download fails

Copy download link

like:

https://az764295.vo.msecnd.net/stable/6c3e3dba23e8fadc360aed75ce363ba185c49794/code_1.81.1-1691620686_amd64.deb

l Then replace the address before the /stable address with the following content:

vscode.cdn.azure.cn <--------This is the one on the left

l The updated address is:

https://vscode.cdn.azure.cn/stable/6c3e3dba23e8fadc360aed75ce363ba185c49794/code_1.81.1-1691620686_amd64.deb

4. Install vscode in the terminal

sudo dpkg -i code_1.81.1-1691620686_amd64.deb

Plug-ins that require vscode installation

①Chinese (Simplified) Language Pack for Visual Studio Code (Configure Chinese)

Enter “Chinese (Simplified) Language Pack for Visual Studio Code”

Click Restart Now

② Code Spell Checker:

Once this plug-in is installed, you don’t have to worry about it. You will find its benefits when there are misspellings of words in your code, because after all, we write code with a large number of variable definitions of English words, and the plug-in can also provide incorrect spellings. Word suggestions. If the word is wrong, a wavy line will appear below it

③Git-lens plug-in for multi-person team collaboration (optional or not): (click for reference)

GitLens can be rich in functionality. I personally use this plug-in to check the authors of different contents in each file and automatically synchronize the remote. Using the git support that comes with VScode is enough for personal development, but it is still slightly insufficient when dealing with file conflicts during team collaboration. At this time, we can use the GitLens plug-in in VScode

④View Git history (using Git Graph): (click for reference)

Git Graph can visualize commits and branches, and create branches, switch branches, merge branches, submit commits and other operations by clicking. Greatly simplifies the operation difficulty.

⑤C/C++ Extension Pack:

C/C++ extension package, download and install directly. It contains the plug-ins (C/C++, C/C++ Themes, CMake) needed for vscode to write C/C++ projects. Compared with before, you don’t need to use them one by one. found.

⑥C/C++ Themes (theme plug-in), c/c++ syntax highlighting configuration file of vscode color matching plug-in (C/C++ Extension Pack download comes with it):

You can set syntax highlighting such as const, enum, typedef aliases, structure references, etc. Needless to say, the keywords of the language itself are much richer than popular plug-ins such as one dark pro.

⑦C/C++ (C/C++ Extension Pack download comes with it):

The official C/C++ plug-in from Microsoft is a necessary plug-in. If it is not installed, the code cannot jump and there is no automatic completion.

⑧CMake (C/C++ Extension Pack download comes with it):

CMake syntax highlighting and auto-completion

?

⑨CMake Tools:

The function of CMake Tools is mainly to use CMake in combination with VSCode IDE, such as generating CMake projects, building CMake projects, etc.

New cmake project

F1 opens the command panel of VSCode, then enter cmake:q, VSCode will automatically prompt based on the input, and then select CMake: Quick Start

Choose the right compiler

Enter the project name as prompted:

Choose whether the project creates a library or executable

VSCode will generate a CMake project for you

l The build folder is the output folder of the cmake command

l CMakeLists.txt file generated by default

l Main.cpp file generated by default

Compile project

Can be executed from the command line:

cd build
cmake..

You can also click Build at the bottom:

Reference URL: https://blog.csdn.net/jiasike/article/details/107474368

Debugger

① Go to compile that point and create the launch.json file.

1. Select node.js debugger

The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly.

2. Then click Add Configuration.

3. A launch.json is generated here, and the one before program $ is deleted

Change to

“program”: ” ${workspaceFolder}/a.out”,

launch.json file:

{
    // Use IntelliSense to learn about related properties.
    //Hover to see the description of an existing property.
    // For more information, please visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) start",
            "type": "cppdbg",
            "request": "launch",
            //"program": "${workspaceFolder}/bulid/STCleanCar.js",
            "program": "${workspaceFolder}/a.out",
            "args": [],
            "stopAtEntry": false,
            //"cwd": "${fileDirname}/bulid",
            "cwd": "${workspaceFolder}/bulid",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable neat printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set disassembly style to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

②Create tasks.json

1. Press F1 to enter the command interface

2. Select the configuration task (if there is none, enter tasks to search, select the configuration task: configure tasks)

Or click on the terminal

At this time, as shown in the picture above, tasks.json is generated. Then we open launch.json to make a comparison. We first add a line of code “preLaunchTask” after launch.json. This line of code means the name of the task that is run before launch. , this name must be consistent with the task name in tasks.json, as shown in the figure below. The label in tasks.json must be exactly the same as the preLaunchTask in launch.json, because the system will use this line before executing launch.json The code first executes the content in tasks.json. It can be simply understood that the code in tasks.json will help us compile and generate an executable file using g++/gcc, while the code in launch.json will let the system debug us. executable file.

*Then use the template to create tasks.json*

tasks.json file:

{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ generates active files",
"command": "/usr/bin/g + + ",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Compiler: /usr/bin/g + + "
}
]
}

*Reference**Link: **https://blog.csdn. net/qq_45049586/article/details/104684343*

Then click to debug

③ Or generate the program directly in the compiler below, but breakpoint debugging is not possible

It can be successfully generated when the exit code is 0, otherwise it is unsuccessful.

Then run

The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly.

Git usage of Vscode

1. Create a remote warehouse

You can first create a new warehouse in your own git, the company’s git website: http://192.168.13.200/

Second, Git permanently saves usernames and passwords

When using Git, you often encounter situations where you need to enter your password frequently. Every git push and git pull requires you to enter your username and password, which is very inconvenient if you submit frequently.

1. Set Git global settings in the terminal:

git config –global user.name “username”

git config –global user.email “User Email”

2. Set up VSCode to remember your git account and password:

git config –global credential.helper store

3. Just close and reopen vsCode

Three, git pushes local code to the remote warehouse

1. First open the corresponding directory to be uploaded

2. Enter the command git init in the terminal to create a local warehouse

You can run the project directly under vscode, and you can use the shortcut keys:

ctrl + ·

Note: This dot is the one under esc on the keyboard;

ps: If there is any problem with Reinitialized existing Git repository in,

① Reason for the error: A .git file already exists in the path.

②Solution: You can enter ls-a in the console under the current file to view it. If there is .git, use rm -rf .git to delete it and then re-initialize git init.

3. Enter the command git add in the terminal. Submit the code to the staging area (git add. Submit all files to the local warehouse by default)

4. Enter the command git commit -m’commit instructions and notes’ in the terminal to submit the staging area code to the local warehouse

5. Enter the command git remote add origin + remote warehouse address in the terminal to bind the remote warehouse

l Note: You only need to enter the current command when pushing to the remote warehouse for the first time

6. Enter the command git push -u origin master in the terminal to push the local warehouse to the remote warehouse (you must enter your account and password)

7. Then refresh in your own warehouse to see if there are any updates

8. Simple commands:

git init
git add .
git commit -m 'Commit instructions notes'
git remote add origin + remote warehouse address
git push -u origin master

Four, VS Code resolves Push (submit) conflicts

When different users modify the same line of the same file and then push it, there will be a conflict. At this time, you need to manually tell git which modification to retain to resolve the conflict.

When there is a conflict, git will directly remind you which line has a conflict. After determining which line you want to determine, save and submit it.

1. Pull the code first (conflicts are found)

2. Manually select the changes that need to be retained (leave the code that needs to be retained and click on the result you want)

(Modifications can also be completed in the merge editor)

3. If you encounter an error conflict problem, you need to submit a commit again after confirming your selection

Enter the command git commit -m’Submit instructions and notes’ to submit the staging area code to the local warehouse, and then submit it

Reference URL:

https://blog.csdn.net/weixin_46535880/article/details/119155123

Five, git clone the remote warehouse code to local

1. Open the target file directory to be cloned

2. Enter the command git clone + remote warehouse address

3. Then continue to enter the command code in the current folder. Open the file directory in vscode

4. Switch current branch (new)

By default, the default branch is opened as the master branch, but if necessary, create a new branch and switch

After creating a new branch

Six, VS Code pushes the code to the remote warehouse for the second time

(If git is not displayed, you can click Save first)

! Simple method:

①Click the submit button

②Click to synchronize changes

③Click OK

④Enter account password

l Possible problems: It should be an error in entering the account and password.

1. Click to select Git workspace

\2. Add files to the staging area

Method 1: Click the plus sign at the change location

Method 2: Select Changes > Stages All Changes to add files to the staging area

\3. Select Commit > Commit All to submit the staging area files to the local warehouse.

That is, git is shown in the figure

l Problems encountered: git submission code keeps loading

Solution:

Exit and restart vscode

\4. Select push to push the local warehouse to the remote warehouse

Seven, VS Code pulls the remote warehouse code

1. Select Pull,Push>Pull from

2. Select the pull warehouse address

3. Select the pull branch

Eight, local warehouse operation

When Git in VScode modifies files that have been tracked in the warehouse, there will be three file statuses. As shown in the picture:

M (Modify), indicating that the file has been modified

D (Delete), indicating that the file is deleted

U (Update), indicating that the file is newly added

For M files:

Select a file to see changes that have been made

Next, you can process these changes. You can choose to abandon the changes or save the changes. If you choose to abandon the changes, the file will roll back to the last saved version.

You can also click the icon above to process all changes

We choose to save all modifications, and all modified files will be saved to the temporary storage area. The corresponding git command is git add.

Next, submit the changes in the temporary storage area to the local repository, click the “√” above, corresponding to the git command git commit, and then add message.

At this time all modifications have been processed

Then continue to push (just push once)

Nine, merge branches

! Conflict

Select the code you want to save

After merging changes, if it is code from another branch, you need to select “Staging Changes” in the merge update

After making changes, just submit as before

The problem I encountered: Because the code of this branch is not saved, I need to merge the branch after submitting it.

Check whether the git record is merged

Reference URL: https://blog.csdn.net/weixin_44004835/article/details/118908695

Ten, view Git history (using Git Graph)

Git Graph can visualize commits and branches, and create branches, switch branches, merge branches, submit commits and other operations by clicking. Greatly simplifies the operation difficulty.

1. First open vscode, click on the plug-in manager on the left, enter the plug-in panel, search for Git Graph and install it.

2. After downloading, click git here to open Git Graph

Git Graph can also be found from the lower left and can be entered by clicking on it.

3. Switch branches

4. If the git warehouse changes, you can click the refresh button in the upper right corner to refresh.

5. Click on a commit to expand the details of the commit and which files were modified.

Eleven. Basic usage

1. Git View file modification timeline and compare file modification content:

2. Undo the local commit and push back to the old version

Make sure you haven’t modified the file yet

Reference URL: https://blog.csdn.net/xaiolele/article/details/125126671

Twelve, GitLens plug-in for multi-person team collaboration (optional or not)

GitLens can be rich in functionality. I personally use this plug-in to check the authors of different contents in each file and automatically synchronize the remote. , using the git support that comes with VScode is enough for personal development, but it is still slightly insufficient when dealing with file conflicts during team collaboration. At this time, we can use the GitLens plug-in in VScode.

There is a log next to each line of code after clicking

Open GitLens

When you enter for the first time, you will be prompted to set up.

At this time, you can use the default settings. (I haven’t encountered it)

Of course, you can also view all logs. In the left menu bar of VsCode, click the GitLens icon to view History (this function can be found in)

But I personally feel that using Git Graph to view history is better and more beautiful.

Reference URL: https://zhuanlan.zhihu.com/p/363064231

Thirteen, benefits compared to terminal push

  1. Code conflicts can be modified manually when found

  2. More convenient and intelligent viewing of historical upload and modification records

  3. Convenient for multiple people to work together to write code

Possible errors:

l fatal: Not a git repository (or any of the parent directories): .git

The prompt says that there is no such directory as .git because git has not been initialized. The solution is as follows:

Just git init!

In other words, after typing git init and pressing Enter on the command line, re-execute the command to add files.

Basic usage of code

After entering the code, select the corresponding function and press tab to supply it.

You can click on the keyboard operation method here to learn about the shortcut keys (the shortcut key is: ctrl + s to open it directly)

VSCODE common shortcut keys FOR LINUX

1. Basic editing

Shortcut keys Function
Ctrl + C Copy
Alt + up/down Move lines up and down
Shift + Alt up/down Copy the current line above and below the current line
Ctrl + Shift + K Delete line
Ctrl + Enter Insert a new line below the current line
Ctrl + Shift + Enter Insert a new line on the current line
Ctrl + Shift + \ Match the closing position of the curly brace, jump
Ctrl + ] / [ Line indent
Home Cursor jump Go to the beginning of the line
End The cursor jumps to the end of the line
Ctrl + Home Jump to the top of the page
Ctrl + End Jump to the bottom of the page
Ctrl + up/down The row view is offset up and down
Alt + PgUp/PgDown The screen view is offset up and down Move
Ctrl + Shift + [ Collapse area code
Ctrl + Shift + ] Expand region code
Ctrl + K /Ctrl + [ Collapse all sub-region codes
Ctrl + k /Ctrl + ] Expand all collapsed sub-area codes
Ctrl + K /Ctrl + 0 Collapse all area codes
Ctrl + K /Ctrl + J Expand all collapsed area codes
Ctrl + K /Ctrl + C Add line comment
Ctrl + K /Ctrl + U Delete line comment
Ctrl + / Add closing line comment
Shift + Alt + A Block area comment
Alt + Z Add closed word inclusion

2. Navigation

Shortcut keys Function
Ctrl + T List all symbols
Ctrl + G Jump line
Ctrl + P Jump to file
Ctrl + Shift + O Jump to symbol
Ctrl + Shift + M Open the problem display panel
F8 Jump to the next error or warning
Shift + F8 Jump to the previous error or warning
Ctrl + Shift + Tab Switch to the recently opened file
Alt + left / right Backward, forward
Ctrl + M Enter using Tab to move focus

3. Query and replace

Shortcut keys Function
Ctrl + F Query
Ctrl + H Replace
F3 / Shift + F3 Query next/previous
Alt + Enter Select all items that appear in the query
Ctrl + D Match the currently selected word or line, select again – operational
Ctrl + K Ctrl + D Move the current selection to the position of the next matching selection (cursor selected)
Alt + C / R / W

4. Multi-line cursor operation on selection

Shortcut keys Function
Alt + Click Insert cursor – supports multiple
Shift + Alt + up/down Insert cursor up and down – supports multiple
Ctrl + U Undo the last cursor operation
Shift + Alt + I Insert Cursor to all line terminators in the selected range
Ctrl + L Select the current line
Ctrl + Shift + L Select all lines that appear in the current selection – Operation
Ctrl + F2 Select all lines that appear in the current selection Currently selected vocabulary – operation
Shift + Alt + right Expand and select the entire line from the cursor
Shift + Alt + left Shrink the selection area
Shift + Alt + (drag mouse) Mouse drag area, insert the cursor at multiple line terminators at the same time
Ctrl + Shift + Alt + (Arrow Key) It is also the [direction of inserting the multi-line cursor] Key control]
Ctrl + Shift + Alt + PgUp/PgDown It also inserts a multi-line cursor [full screen effect]
Shift + Alt + mouse selection block Multi-line block selection editing

5. Rich language operations

Shortcut keys Function
Ctrl + Space Input suggestions [intelligent prompts]
Ctrl + Shift + Space Parameter prompts
Tab Emmet command trigger/indent
Ctrl + Shift + i Format code
Ctrl + K Ctrl + F Format the selected part of the code
F12 Jump Go to definition
ctrl + – Jump back to the original position (position before jump)
Alt + F12 Code snippet shows definition
Ctrl + K F12 Open definition in other window
Ctrl + . Quickly fix some syntax errors that can be fixed
Shift + F12 Show all references
F2 Rename symbols
Ctrl + Shift + . / , Replace with next value
Ctrl + K Ctrl + X Remove whitespace characters
Ctrl + K M Change page document format

6. Editor management

Shortcut keys Function
Ctrl + F4, Ctrl + W Close the editor
Ctrl + k F Close the currently open folder
Ctrl + \ Cut editing window
Ctrl + 1/2/3 Switch focus on Different cutting windows
Ctrl + K Ctrl <-/-> Switch focus to different cutting windows
Ctrl + Shift + PgUp/PgDown Switch tab position
Ctrl + K <-/-> Cutting window position exchange

7. File management

Shortcut keys Function
Ctrl + N New file
Ctrl + O Open file
Ctrl + S Save file
Ctrl + Shift + S Save as
Ctrl + K S Save all currently open files
Ctrl + F4 Close the current editing window
Ctrl + K Ctrl + W Close all editing windows
Ctrl + Shift + T Undo a recently closed file editing window
Ctrl + K Enter Keep it open
Ctrl + Shift + Tab Call up the list of recently opened files. Repeated pressing will switch
Ctrl + Tab with the above Consistent, the order is inconsistent
Ctrl + K P Copy the storage path of the currently opened file
Ctrl + K R Open the current editing file storage location [File Manager]
Ctrl + K O In the new editor Open the currently edited file

8. Display

td>

Shortcut keys Function
F11 Switch full screen mode
Shift + Alt + 1 Switch editing layout [currently invalid]
Ctrl + =/- Zoom in/out
Ctrl + B Show and hide the sidebar
Ctrl + Shift + E Focus switching between resource view and editing view
Ctrl + Shift + F Open global search
Ctrl + Shift + G Open Git visual management
Ctrl + Shift + D Open the DeBug panel
Ctrl + Shift + X Open the plug-in market panel
Ctrl + Shift + H Replace query and replace in the current file
Ctrl + Shift + J Open detailed query
Ctrl + Shift + V Preview Markdown file [after compilation]
Ctrl + K v Open the rendered view in the sidebar [New]

9. Debugging

Shortcut keys Function
F9 Add release breakpoint
F5 Start debugging and continue
F11 / Shift + F11 Single step into/single step out
F10 Single step over
Ctrl + K Ctrl + I Show suspension

10. Integrated terminal

td>

Shortcut keys Function
Ctrl + ` Open integrated terminal
Ctrl + Shift + ` Create a new terminal
Ctrl + Shift + C Copy selected
Ctrl + Shift + V Copy to currently active terminal
Shift + PgUp / PgDown Scroll the page up and down
 |

| Ctrl + Shift + V | Preview Markdown file [after compilation] |
| Ctrl + K v | Open the rendered view in the sidebar [New] |

9. Debugging

Shortcut keys Function
F9 Add release breakpoint
F5 Start debugging and continue
F11 / Shift + F11 Single step into/single step out
F10 Single step over
Ctrl + K Ctrl + I Show suspension

10. Integrated terminal

td>

Shortcut keys Function
Ctrl + ` Open integrated terminal
Ctrl + Shift + ` Create a new terminal
Ctrl + Shift + C Copy selected
Ctrl + Shift + V Copy to currently active terminal
Shift + PgUp / PgDown Scroll the page up and down
Ctrl + Home / End Scroll to the top or bottom of the page