Link Search Menu Expand Document

Lecture 3 - Editors (Vim)


View lecture View lecture notes

Exercises


  1. Complete vimtutor. Note: it looks best in a 80x24 (80 columns by 24 lines) terminal window

    Type vimtutor in the terminal. It will take around 25-30 minutes to get through all the 7 chapters.

    The terminal can be resized by changing your terminal settings accordingly. I have outlined the process for Windows Terminal (which I use) below.

    • Click on the ‘Settings’ option in dropdown.

    Click on the 'Settings' option in dropdown

    • Scroll down to the bottom of the ‘Startup’ tab.

    Scroll down to the bottom of the 'Startup' tab

    • Adjust the number of columns and the number of rows and click on ‘Save’.

    Scroll down to the bottom of the 'Startup' tab

    • Close ‘Windows Terminal’ and restart the application.
  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.

    wget is a command line tool that can be used to download files from the web. It supports HTTP, HTTPS and FTP.

    wget https://missing.csail.mit.edu/2020/files/vimrc; mv vimrc ~/.vimrc
    

    Then you can go on to read the contents of the .vimrc file.

    vim ~/.vimrc
    
  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.

    Self-explanatory.

  4. To practice using Vim, re-do the Demo from lecture on your own machine.

    Self-explanatory.

  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.

    Self-explanatory.

  6. Configure your other tools to use Vim bindings (see instructions above).

    • Shell -
      For zsh add the following lines to ~/.zshrc

        bindkey -v
        export KEYTIMEOUT=1
      

      This video talks about how to enable and use Vi mode in both bash/zsh.

    • Browser -
      I am a Brave user which is based on Chromium. For browsers based on Chromium you can simply install the Vimium plugin and adjust settings according to your needs.

  7. Further customize your ~/.vimrc and install more plugins.

    Self-explanatory.

  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.

    Will be updated soon.