Create ‘modes’ (normal, insert and quit) and statusline
Display what you type after insert mode
Add print organized
Create member functions to manipulate the backspace key and other keys
Add cursor movement
Manipulating the delete, key_enter and tab key:
Improving the status line
Opening and saving files
Watch video
Source code on GitHub:
Let’s go write the code!
01. STARTING BASIC PROJECT
Create project and basic files
minivim.hpp
minivim.cpp
main.cpp
Makefile
Compile and run to test!
02. GET FILE VIA COMMAND LINE
If there is a file it will be the file name, if not it will be untitled.
minivim.hpp
Add to minivim.cpp and change the constructor:
Change the printw:
Change main.cpp:
Compile and run to test!
03. DISPLAY WHAT YOU TYPE ON THE SCREEN
Do it this way temporarily just to see if everything is right
Change minivim.hpp:
Change minivim.cpp:
Compile and run to test!
04. CREATE ‘MODES’ (NORMAL, INSERT and QUIT) and STATUSLINE
Now let’s start writing our MiniVim!
Change minivim.hpp:
Change minivim.cpp, initialize members:
Create MiniVim::update():
Create MiniVim::statusline():
Change MiniVim::run():
Compile and run to test!
05. DISPLAY WHAT YOU TYPE AFTER INSERT MODE
Manipulate data.
Change minivim.hpp:
Change minivim.cpp:
Add a new switch inside case 'n':
Add a switch inside case 'i':
Add loop to end of member function:
Change and add to run():
Compile and run to test!
06. ADD PRINT ORGANIZED
Map keys and coordinates
Change minivim.hpp:
Remove codes from minivim.cpp and then add in place of push_back():
Create content for MiniVim::print():
In this way, so that there is no segmentation fault when we create the file opening routine
Add to run():
Compile and run to test!
07. CREATE MEMBER FUNCTIONS TO MANIPULATE THE BACKSPACE KEY AND OTHER KEYS
Change minivim.hpp adding member functions:
Create execution of all of them:
Create a case right after case 'i':
08. ADD CURSOR MOVEMENT
Change minivim.hpp adding the member functions:
Create content:
Add to start of input(int c):
09. MANIPULATING THE DELETE, KEY_ENTER and TAB KEY:
Delete key:
Enter key
Tab key:
10. IMPROVING THE STATUS LINE
Let’s monitor the cursor position and add colors and features!
Create a member named std::string section
Initialize in the constructor as empty: section = {};
Add to the end of the update() function:
Print on statusline():
Make the slash long, add to statusline() right after attron(A_REVERSE);:
Add colors, include in the constructor after initscr and other declarations: use_default_colors(); and in statusline():
11. OPENING and SAVING FILES
Add to minivim.hpp:
Add this code to the constructor before initscr();:
To save files first add this member function as protected to minivim.hpp:
Create the run in minivim.cpp:
And then change in MiniVim::input(int c):
Now it’s ready and you can run all the tests!
Watch video
If you want to see the entire process created here on video, I suggest watching the video below. Despite being in Portuguese, it is possible to follow the step by step regardless of the language.
Comments