21 Jan 2019

VIMing on Mac

Contents

What is it about?

I have been using VIM to write C++ as well as python code for years. However, after I upgraded my Mac a few days ago, I had to redo the entire setup one again. Yes, one might say that it should be as simple as copying the .vimrc file but such is not the case.

In this post, I describe how one could turn VIM into a powerful python IDE. This is a live page and I will keep updating it as I find better plugins and tools. That being said, the information given here is compiled by me and this setup suits my workflow. There are tons of other posts on the Internet catering to the same use case and it is up to you to decide what works for you.

Steps

Install MacVim

Grab the latest version of MacVim directly for their releases page

Basic indentation settings for python

Add the following lines to the .vimrc file in your home directory

filetype plugin indent on
syntax enable
au BufNewFile,BufRead *.py
     \set tabstop=4
     \set softtabstop=4
     \set shiftwidth=4
     \set textwidth=79
     \set expandtab
     \set autoindent
set encoding=utf-8
set fileformat=unix
set backspace=indent,eol,start

Install Vundle

Vundle is a great plugin manager for VIM. Install it using the official instructions or using the following steps:

  1. Clone the repo

     git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
    
  2. Add the bundle directory to VIM’s runtime path by adding the following line at the beginning of the .vimrc file located in your home folder.

     set rtp+=~/.vim/bundle/Vundle.vim
     call vundle#begin()
     call vundle#end()
    

Install VIM plugins

  1. YCM

    There are two components to installing YCM. First is the client which can be installed using Vundle and second is the server which has to be compiled (this would require installing X-code and the command-line tools).

    1. Install YCM client by adding the following line in .vimrc and executing :PluginInstall in vim.

       call vundle#begin()
       Plugin 'Valloric/YouCompleteMe'
       call vundle#end()
      
    2. Install XCode if you already have not

       $ xcode-select --install
      
    3. Build the YCM server

       cd ~/.vim/bundle/YouCompleteMe
       ./install.py --all
      

    NOTE: See YCM’s documentation to enable Jedi based autocomplete in virtual environments

  2. ALE

    1. Add the following line between call vundle#begin() and call vundle#end() in the .vimrc and execute :PluginInstall

       Plugin 'w0rp/ale'
      
    2. Install linters and fixers

      Install autopep8 or flake8 using pip: pip install autopep8 or pip install flake8.

      Install the yapf fixer: pip install yapf

      Use the following configuration lines in .vimrc

       let g:ale_fixers = {'python': ['yapf']}
       let g:ale_fix_on_save=1
      

To be update….


Tags:
0 comments