Vim Plugin Instructions for Simulating an IDE on a Remote Cluster

If you want to develop code while connected to a remote cluster, you unfortunately can't use an IDE in most cases. You can use vim plugins, however, for inline code linting and tab-completion. This guide will take you through the process of installing a vim plugin manager and several useful plugins and updating your version of vim locally.

1. Set up a plugin manager

I use vim-plug but other popular options are vim-pathogen or Vundle. To install vim-plug:

  1. cd ~
  2. curl -fLo ~/.vim/autoload/plug.vim --create-dirs
  3. Open your ~/.vimrc and add the following:
  4. #Plugins will be downloaded under the specified directory.
    call plug#begin('/home/albert.einstein/.vim/plugged')
    Plug 'Valloric/YouCompleteMe'
    Plug 'nvie/vim-flake8'
    Plug 'air blade/vim-gitgutter'
    #List ends here. Plugins become visible to Vim after this call.
    call plug#end()

  5. Write and close your ~/.vimrc. Reopen it and :PlugInstall. Another window will pop up showing the progress of the installation of the three plugins we added.
  6. When the installation is complete, just exit vim normally.

vim-flake8 is a python linter, YouCompleteMe is a tab-completion plugin, which is as close as you can get to an IDE on a cluster, and vim-gitgutter tracks changes to git version controlled files in the gutter, which is the area with signs on the left side of a vim window

2. Install flake8

Flake8 is a python style guide enforcer that reads your .py files and catches style warnings and errors. You can use it on its own or within vim.

  1. Check if it's already installed with which flake8.
  2. pip install --user flake8
  3. Run flake8 on any .py file and you will see a list of errors and warnings.
  4. E402 module level import not at top of file E402 module level import not at top of file E302 expected 2 blank lines, found 1 E226 missing whitespace around arithmetic operator E305 expected 2 blank lines after class or function definition, found 1 E226 missing whitespace around arithmetic operator

  5. Run flake8 in vim directly by opening the file and pressing . The list of warnings will pop up in a quickfix window. Press Ctrl-W j to jump to the quickfix window to scroll through the errors. When you're done, :ccl will close the window.
  6. You can choose which errors you want to suppress in your flake8 config file. This will change the options both for running flake8 from the command line and within vim. Mine is saved in ~/.flake8 and has the following options:
  7. [flake8]
    ignore = E231,W191
    max-line-length = 150

    You need to start the file with [flake8] but the exclusions are up to you. I've suppressed warnings that I'm missing a space after a comma and that the indentation includes a tab. flake8 tells you the warning numbers in the output. If you now run flake8 on the same file, you'll see that those warnings are no longer output.

3. Update vim locally and make YouCompleteMe

If you opened a file with vim to try flake8, you may have seen the warning message YouCompleteMe unavailable: requires Vim 7.4.1578+. If you run vim --version, you will see that the version installed on the cluster is <7.4.1578, which means we can't use YouCompleteMe. However, we can just build vim from scratch locally! If you want to skip this step, just remove Plug 'Valloric/YouCompleteMe' from your vimrc and this warning message will disappear.

  1. cd to wherever you want to download the source. It can't be /home/albert.einstein/.local/bin
  2. Make vim
  3. git clone
    cd vim
    ./configure --with-features=huge \
    --enable-multibyte \
    --enable-rubyinterp=yes \
    --enable-pythoninterp=yes \
    --enable-python3interp=yes \
    --enable-perlinterp=yes \
    --enable-cscope \
    make VIMRUNTIMEDIR=/home/albert.einstein/.local/share/vim/vim80
    make install

    The installation guide I consulted also has --with-python-config-dir=/usr/lib/python2.7/config passed as an option to the ./configure command, but I couldn't find the config.c files for the cluster installation of python and leaving this out doesn't seem to be causing any problems yet.

  4. Finish installing YouCompleteMe
  5. cd ~/.vim/plugged/YouCompleteMe
    ./ --clang-completer

    or if you don't need semantic support for C-based languages:

    cd ~/.vim/plugged/YouCompleteMe

  6. Set an alias in your .bashrc file to point to your local copy of vim alias vi='/home/albert.einstein/.local/bin/vim'.

Don't forget to source your .bashrc and change all instance of albert.einstein to your username. You can check that you are indeed running the newer version of vim by running vi --version (or whatever you set as your alias). Please note that this quickstart guide is just meant to help you get things set up, and you should consult the documentation for the three plugins we installed for more information, troubleshooting, and tutorials.