Vim G++
Vim G++
Vim G++
md 2024-02-12
Opening Vim: Open your terminal and type vim filename.cpp to start writing a new C++
program. Replace filename.cpp with your desired file name.
Entering Insert Mode: Press i to enter insert mode. In insert mode, you can type your code as you
would in any text editor.
Saving and Exiting: Press Esc to return to normal mode.Then enter :wq or press ZZ to save your file
and quit Vim simultaneously.
If you have Vim installed, you can use the vimtutor program to learn and get comfortable with Vim.
vimtutor is a 30-minute interactive tutorial for beginners that teaches the fundamentals of Vim, such as
inserting text, deleting text, and searching within files. To start it, simply open your terminal and type
vimtutor.
h: Move left
j: Move down
k: Move up
l: Move right
Jumping Around
/
lab.md 2024-02-12
Searching
Editing Commands
Editing .vimrc: Open .vimrc with Vim by running vim ~/.vimrc from your terminal.
Reloading .vimrc: After saving your changes, you can apply them without restarting Vim by running
:source ~/.vimrc.
Basic Compile Command: In the terminal, type g++ filename.cpp -o outputname where
filename.cpp is the name of your C++ file, and outputname is the name of the executable to be
created.
Running Your Program: After compiling, run your program by typing ./outputname in the
terminal.
The GNU Debugger (gdb) allows you to see what is going on inside another program while it executes or
what another program was doing at the moment it crashed.
Compiling for gdb: To use gdb, you need to compile your program with the -g option. This includes
debugging information in the executable. Example: g++ -g filename.cpp -o outputname.
Starting gdb: Type gdb outputname in the terminal.
Common gdb Commands:
run: Start your program.
break main: Set a breakpoint at the beginning of the program (you can replace main with any
function name or line number).
next: Execute the next program line (after stopping at a breakpoint).
print variable_name: Print the current value of a variable.
continue: Continue running the program until the next breakpoint.
quit: Exit gdb.
Please try out and get comfortable with using these tools on your own computers as the lab exam will be
held on computers that have only these tools installed on them.
1. Write your code in Vim: Open Vim and write your C++ code.
2. Compile your code with g++: Use the g++ compiler to turn your code into an executable.
3. Debug your code with gdb: If your program isn't working as expected, use gdb to step through your
code and find the issue.