Day 41: Algorithms… We meet again.

Today was a bit of a mixed bag. I did a little bit of a few different things which wasn’t the most productive. I did however find a good set of lecture notes for algorithms and data structures. The last time I covered them was through an 8 hour YouTube video. It was solid but also didn’t help me build a process for solving algorithm problems. I hope that this time around goes better.

TLDR;

Okay, so here are the highlights of what I did:

  • I read the first section in a series of lecture notes on Data Structures and Algorithms from the University of Birmingham. It seems like the PDF covers the core topics and try to break down the ideas rather than just the solutions. I hope it works and helps me improve in this aspect.
  • I read through some of the Vimscript book to try and get better at configuring Vim. I found a great little code snippet for locally or globally renaming variables / functions that I wanted to add to my config file. I thought this would be a great opportunity to slowly start learning how to configure everything else while I’m at it.
  • I went through some example programs in awk to help me get faster at utilizing the program.

Notes on Vimscript


Where is My .vimrc File Located

To easily find the location and name of the file on any operating system, run :echo $MYVIMRC in Vim. The path will be displayed at the bottom of the screen.

If a .vimrc file does not exist in the user’s home directory we can just write one and save it as:

  • ~/.vimrc for Mac and Linux systems
  • _vimrc for windows systems (Since I am using cigwyn to emulate a Linux system on top of Windows I am just using ~/.vimrc)

Logging Output in Vim with :echom

When you’re writing more complicated Vimscript later in this book you may find yourself wanting to “print some output” to help you debug problems. Plain old :echo will print output, but it will often disappear by the time your script is done. Using :echom will save the output and let you run :messages to view it later.

Commenting with VimScript

We can add comments using the " character. There are times where it won’t work but most often it does.

Setting Options with set

There are two main kinds of options that we can set in Vim.

  1. Boolean options i.e. :set <name> (Only has two potential values like a switch)
  2. Options that take a value (They have multiple values that can be accepted for the option)

We can also toggle the values for Booleans options like this.

" Sets Vim to have line numbers along the side of the window
:set number

" Sets Vim not to have line numbers
:set nonumber

" Sets Vim to toggle to the opposite of the current value
:set number!

" Displays the options value current value
:set number?

We can set the value of non-boolean options with a slightly different syntax:

:set <name>=<value>

" Example with numberwidth - set the numberwidth to 4 columns
:set numberwidth=4

" View what the numberwidth values is currently
:set numberwidth?

We can also set multiple options all on the same line with one :set command:

:set numberwidth=2
:set nonumber
:set number numberwidth=6

Options List

  • number
  • numberwidth
  • wrap
  • shiftaround
  • matchtime

References


Conclusion

That’s all for today. If you are interested in the MIT course you can check out the video lecture I’m currently going through. The lecture is helpful but isn’t sufficient by itself. Anyways, until next time PEACE!