
-
more git patterns
- what if the upstream is updated after we fork?
-
functional programming in python
map
,filter
,lambda
- (optional reference) realpython
- list comprehensions
- (optional reference) Corey Shafer youtube video
- (optional reference) realpython
- (optional reference) python documentation
-
memory management in python
- local vs global variables
- (optional reference) realpython
- local vs global variables
Pre-lab work:
-
Ensure that you have completed the entire lab for
topic_00
before completing this lab. -
Spend at least 20 minutes reviewing how to use vim effectively. You can either:
- re-do the vimtutor tutorial from last pre-lab, or
- try the more interactive tutorial at https://www.openvim.com/.
Instructions:
-
In the previous lab, you forked the class repository. Since then, however, I have made updates to the class repo, and those updates won't be reflected in your forked repo. In this first task, you must update your forked repo so that it has all the content of my upstream repo.
Use the following flowchart to help you get the commands correct:
Note that the steps with "negative numbers" are events that have already happened, steps with "zero numbers" are events that you only have to run once to setup your local repo. Every time you need to update your repo, you will start with step 1.
-
In this task you will setup the
@p
macro for debugging python programs.-
Ensure that you have updated your local git repo with the latest upstream.
-
cd
into thetopic_01_functions
folder and then open the filep_macro
in vim. You should see contents that look like^y$iprint("^[A=", ^[pa)^[^
This is the "source code" for the macro, and is the sequence of key presses that will be sent to vim whenever you activate the macro. The
^[
characters should appear in a slightly different color, and if you move your cursor over them, you'll notice they behave like a single character. This is how theEsc
key gets rendered in the terminal, so each of these characters will cause theEsc
key to be pressed. -
Copy the line into the
p
register by typing the following sequence of commands in normal mode. (Ensure that you are in normal mode by pressingEsc
before typing the commands.)"pyy
The
yy
yanks (vim's language for copying) the entire line, and the"p
indicates that we are yanking into thep
register (vim's language for clipboard). Your typical muggle text editor has only a single clipboard to copy/paste from, but vim has a separate register for every key on the keyboard. This lets us copy/paste many different things at the same time. Macros use the same registers as yanking/pasting, so by yanking into thep
register we are also creating thep
macro. -
To ensure that your macro works, open a new tab with the command
:tabe
You can use the commands
gt
andgT
to switch between tabs.In your new tab, type
python_variable_name
into the tab. With your cursor anywhere on the line, type
@p
to activate the macro. If you've created the macro correctly, you should get the resultprint("python_variable_name=", python_variable_name)
-
(optional) For a detailed reference on writing your own vim macros, see https://vim.fandom.com/wiki/Macros.
-