Git Product home page Git Product logo

vscode_for_cpp's Introduction

VS Code setup for C++ on Windows

Prerequisite to write, build and run a C++ program

Since visual studio code is just a source code editor for multiple language including C++. We need below things to setup a good C++ dev environment.

  • Install VS Code for windows
  • C++ specific formatter which helps while we write code. VS code provides various extensions to help in this such as C/C++ Extensions by Microsoft
  • C++ Compiler(such as mingw) to be used for code compilation

Install VSCode on Windows

Go to VS Code download page and download vscode for Windows and install by double clicking the downloaded installer and following installation steps.

Install C++ Compiler - MINGW

Please do check if MINGW is already installed on your system by running

g++ --verison 

on PowerShell or Command prompt and verify

-> Dont look it in 'Program Files' folder since generally MINGW is installed using copy/paste way and it is copied in C:\MINGW or similar. Even if it is installed using installer it copies at C:\MINGW only. You can also check environment path where it might have been added if it was installed earlier

Now we are ready :)

Now we have editor and compiler, let us write our code, compile, debug and run.

Write Code

VS Code provides various extensions to help with intelligence, indentation, static analysis, formatting etc.

You can open visual studio code extension using [ctrl + shift + x] or View->Extensions. Just for begining, Search for C/C++ extension from Microsoft and install it from vs code itself.

Go to Command Pallete (Ctrl + Shift + P) and select C/C++: Edit Configurations to Add dependent includePath and library path in C_CPP_Properties.json

Build Code

Go to Command Pallete (Ctrl + Shift + P) and select Task: Configure Task to create/modify task.json to configure compiler path, command etc

Launch Code - Debug/Run

Go to Run and Debug in left side bar (Ctrl + Shift + D) and configure program to run and other dependencies by editing launch.json

Please note above build/launch would be created for selected file only therefore make sure .cpp is selected. Also you can compile/run the code using g++ compilation command such as g++ -g -o and run from command line

Go to MINGW download page and download vscode for Windows and install by double clicking the downloaded installer and following installation steps. which will copy mingw installation files at C:\MINGW or C:\MINGW64. Add it to PATH by editing environment variables.

..and these below items really help

keyboard Shortcuts

  • Copy path of active file : Ctrl+K P

  • Reveal active file in File Explorer : Ctrl+K R

  • Show active file in new window/instance : Ctrl+K O

  • Show preview for markdown : Ctrl + K, V

  • Show hover : Ctrl+K Ctrl+I

  • Toggle Panel(Terminal etc) : Ctrl + J

  • Toggle Sidebar(Explorer bar etc) : Ctrl + B

  • Explorer Bar : ctrl + shift + E

  • Select Color Theme : Ctrl K + Ctrl T

  • Extension explorer : ctrl + shift + x

  • Preference(command palette) : ctrl + shift + p

  • Keyboard Binding : Ctrl + k + s

  • Open/Goto file : ctrl + p

  • Select current line : Ctrl+L

  • Line up/Down : ALt + Up/Down

  • Delete Line : Ctrl + shift + k

  • Go to Line number : Ctrl+G

  • Select all occurrences of current selection : Ctrl+Shift+L

  • Go to Definition : F12

  • Peek Definition : Alt+F12

  • Open Definition to the side : Ctrl+K F12

  • Show References : Shift+F12

  • Run - Ctrl + Shift + D

  • Go back / forward : Alt+ โ† / โ†’

  • Select all occurences of Find match : Alt+Enter

  • Select all occurrences of current word : Ctrl+F2

  • Toggle case-sensitive / regex / whole word : Alt+C / R / W

  • Insert line below : Ctrl+Enter

  • Insert line above : Ctrl+Shift+Enter

  • Scroll page up/down : Alt+PgUp / PgDn

  • Add line comment : Ctrl+K Ctrl+C

  • Remove line comment : Ctrl+K Ctrl+U

  • Trigger suggestion : Ctrl+Space

  • Trigger parameter hints : Ctrl+Shift+Space

  • Format document : Shift+Alt+F

  • Format selection : Ctrl+K Ctrl+F

  • Quick Fix : Ctrl+.

  • Toggle word wrap : Alt+Z

  • Focus into 1st, 2nd or 3rd editor group : Ctrl+ 1 / 2 / 3

VSCode Extensions

  • Python, C/C++, Docker by Microsoft
  • GitLens by EricAmodio
  • Zuul Job Browser
  • Pylance by Microsoft

Misc

Ctrl + M : Toggle Use of Tab Key for Setting Focus/and entring space

References

https://code.visualstudio.com/docs/cpp/config-mingw

https://gourav.io/blog/setup-vscode-to-run-debug-c-cpp-code

https://www.youtube.com/watch?v=DIw02CaEusY

https://code.visualstudio.com/docs/editor/variables-reference

vscode_for_cpp's People

Contributors

sunilrpandey avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.