Link Search Menu Expand Document

Homework 02: Editors (Vim)

Due to the nature of editors and preferences, we will not be requiring everyone to use Vim for these problem sets, and you can choose the editor that you wish to use. That being said, it’s highly encouraged to learn a new editor, especially those with a different paradigm than you’re used to. Furthermore, you can optionally use a script or other methods if you feel it’s more suitable. These questions are designed to exploratory in nature and for your own benefit!

Homework Update

Run git pull to grab the latest homework.

Required Questions

  1. To practice using Vim, re-do the Demo from lecture on your own machine. Fix the bugs in the existing file demo.py by modifying it to the following text (refusing the temptation to copy and paste), and submit demo.py.

    def fizz_buzz(limit):
        for i in range(1, limit):
            if i % 3 == 0:
                print('fizz', end='')
            if i % 5 == 0:
                print('buzz', end='')
            if i % 3 and i % 5:
                print(i)
            else:
                print()
    
    def main():
        fizz_buzz(10)
    
    main()
    
  2. Suppose you have a list of things in a file items. Now, we want to number these items sequentially, so that it looks like this:

    1. popcorn
    2. chicken
    3. pizza
    4. taco
    ...
    10. agutuk
    11. alfalfa
    12. amaranth
    ...
    

    Hint: If you’re using Vim, consider looking at :help v_g_CTRL-A. You can find that either in Vim’s built-in help or online.

    Please make a copy of items called items_numbered and make the modifications above. Submit items_numbered.

  3. Convert an XML to JSON using the editor of your choice. In this case, convert example-data.xml to example-data.json. (With Vim, try using Vim macros!) Try to do this on your own, but you can look at the macros section above if you get stuck. (Credits to Missing@MIT for the test file.) Submit example-data.json.

Optional Questions (Vim)

These questions are intended for those who want to learn how to use Vim.

For the curious, Addison’s Neovim configuration can be viewed here.

  1. Complete vimtutor. Note: it looks best in a 80x24 (80 columns by 24 lines) terminal window. There is nothing to be submitted for this problem.
  2. Download Missing@MIT’s basic vimrc and save it to ~/.vimrc. Read through the well-commented file (using Vim!), and observe how Vim looks and behaves slightly differently with the new config.
  3. Install and configure a plugin: ctrlp.vim.
    1. Create the plugins directory with mkdir -p ~/.vim/pack/vendor/start
    2. Download the plugin: cd ~/.vim/pack/vendor/start; git clone https://github.com/ctrlpvim/ctrlp.vim
    3. Read the documentation for the plugin. Try using CtrlP to locate a file by navigating to a project directory, opening Vim, and using the Vim command-line to start :CtrlP.
    4. Customize CtrlP by adding configuration to your ~/.vimrc to open CtrlP by pressing Ctrl-P.
  4. Use Vim for all your text editing for the next month. Whenever something seems inefficient, or when you think “there must be a better way”, try Googling it, there probably is. If you get stuck, come to office hours or send us an email.
  5. Configure your other tools to use Vim bindings (see instructions above).
  6. Further customize your ~/.vimrc and install more plugins.