Lecture 3

  1. Complete vimtutor. Note: it looks best in a 80x24 (80 columns by 24 lines) terminal window.
  2. Download our 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. To practice using Vim, re-do the Demo from lecture on your own machine.

    You can follow the video for the solution

  5. 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.

    If you know HTML, you can practice using vim by cleaning up the files of this very website!

  6. Configure your other tools to use Vim bindings (see instructions above).
  7. Further customize your ~/.vimrc and install more plugins.
  8. (Advanced) Convert XML to JSON (example file) using Vim macros. Try to do this on your own, but you can look at the macros section above if you get stuck.

    In real life you should just ask ChatGPT to do that for you but if you still want to do it with vim here is how:

    1. Download the file and open it in vim.
      curl -O https://missing.csail.mit.edu/2020/files/example-data.xml
    2. Delete first and last tag.
      Gdd ggdd
    3. Insert the first [ at the beginning of the file, the move to the very start of the second line (where the <person> tag is) and start recording the macro in a.
      qa
    4. Format the first person tag:
      ^cf>{ESC
    5. Move to the first item and change it:
      j0^r"f>s": "ESCf<cf>",ESC
    6. Move to the second item and change it:
      j0^r"f>s": "ESCf<cf>"ESC
    7. Move to the second person tag, change it and move to the next line:
      j0^cf>},ESCj0
    8. Close the macro with q and execute it until the end of the file (you should test it with @a before):
      999@a
    9. You can then remove the last comma and add the final closing brakcet (]).