For this lab report, I will be detailing the steps to the vim
challenge in Lab 7. As we all know, vim
is a very powerful yet quite controversial programming language, but after learning the basics and using it for the Skill Demonstration 2 practice, it actually proved itself very handy in my ssh
ieng6
login, where I didn't have access to anything but the command line in Visual Studio Code. A handy tool called vimtutor
showed me the ropes, and it is very helpful at teaching you how to navigate such a daunting interface. Anyways, here is a fun little reminder of the many joys of Vim, although if this is your first time using Vim, please don't worry :)
Credit: https://www.freecodecamp.org/news/how-i-learned-to-love-vim-ce3e058d57fb/
We will use this repository for the purposes of these tasks: https://github.com/ucsd-cse15l-s23/lab7
- Setup Delete any existing forks of the repository I have on my account
- Setup Fork the repository
- Start the Timer!
- Log into
ieng6
- To get to this step, you just need to type
ssh [email protected]
into the command line, and if you don't have anssh key
on your local system, then just enter your password as well.
- Clone my fork of the repository from my Github account
- To clone the fork, use
git clone https://github.com/acjeter/lab7
- Run the tests, demonstrating that they fail
- To run the tests, you must first make sure that you change the working directory by using
cd
tolab7/
or wherever you put the cloned lab7.
- After that, input
bash test.sh
to test the file, the output should show thatListExamples.java
did not pass one of the JUnit testers.
- Edit the code file
ListExamples.java
to fix the failing test (the error is thatindex1
is used instead ofindex2
in the final loop inmerge
- Now, to fix the code, we're going to enter
vim
.Vim
allows us to make command-line edits to a file, and in this case, since there is a bug withListExamples.java
, we will need to entervim ListExamples.java
into the command-line.
- The screen that follows is the
vim
view ofListExamples.java
! How cool! Now, while you might think that vim is able to be navigated by clicking with the curser and making edits just like Visual Studio Code, unfortunately that is not the case. - With vim, you will need to use the
<H>
key to move right,<J>
key to move down,<K>
key to move up, and<L>
key to move left. - To make edits, you need to press
<i>
to enter insert mode. Alternatively, you can press<R>
to replace one character, by typing the character you want to replace it with after. To exitinsert mode
, you simply need to press the<esc>
key to enternormal mode
. - To exit vim altogether without saving your changes, you can type
:q
. To exit AND save your changes, make sure to type:wq
. - Now, lets fix the bug. We will need to move the curser down to the line that contains the bug, which is in the second while loop. For me, I needed to press
<J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><J><L><L><L><L><L><L><L><L><L><L><L> <R><2>
and then I saved and exited vim by typing::wq
. - Now, the second line down in the second while loop should read:
index2 += 2;
, andListExamples.java
should be all fixed!
- Run the tests, demonstrating that they now succeed
- After exiting vim, we will need to re-run the tests, by going up twice in our
bash
history. For me, I was able to re-enterbash test.sh
quickly by typing<up><up><enter>
. The test results of the edits in vim are below:
- Commit and push the resulting change to your Github account
- Finally, to commit the changes you have made to your edited clone, you will need to type and enter
git commit
. This will begin the commit process. After you type this, you will need to inputgit add <file>
for each of the files that bash is telling you need to be added. It looks like this:
Then, it will prompt you into vim to make a change title. To add one press i
and make your changes, and then <esc>
and :wq
to save changes.
Then, use git commit
again and you should see this:
Now, type git push <cloned repository ssh key>
for me it is git push [email protected]:acjeter/lab7.git
. You should see this and it should be complete!
Congratulations! I knew you could do it! I'm looking forward to our next tutorial! :)