Skip to content

vimsetup

cellistigs edited this page Dec 1, 2020 · 1 revision

Script documentation for file: vimsetup, Updated on:2020-11-25 18:44:11.203171

Vim Configuration

Today I spent some time refining my vim configuration. While this does not necessarily belong in this repo, it will be useful for me to refer to throughout my time developing NeuroCAAS, so I am includin the steps that I took and the relevant new functionality here.

Today we installed a vim autocomplete module, 'jedi-vim'. Initially, I tried out kite, which while shiny and new was somewhat obscure to configure and also seemed to have a questionable past. I have gone with jedi-vim because it looks to be a stable and dependable option.

This package has many features for which I will document the api in the near future, but the one I was most interested in was intelligent command completion. The jedi-vim package accomplishes this through the structure of python packages, offering up intelligent suggestions for completion when users type a dot (.). Auto complete more generally can be accomplished by typing as well

Installation

To install this package, I relied upon an existing installation of the pathogen plugin manager. With pathogen, it is easy to install new packages by simply git cloning appropriately structured repositories into the local directory ~/.vim/bundle (you probably want to do this with the --recursive flag to get all dependencies). I installed both jedi-vim and a tab completion package supertab through this method. Note: you can check installed packages by opening vim and entering the commmand :scriptnames at the vim command prompt. I should also note that I had to disable a different plugin, vim-pydocstring, in order to get jedi-vim to work properly.

Configuration

In order to keep autocompletion discreet, I wanted to set autocompletes to trigger only when I pressed tab, as opposed to every time I typed a dot. Doing this involved the following commands, inserted into my .vimrc file:
let g:jedi#popup_on_dot = "0"
let g:SuperTabDefaultCompletionType = "context"

The first silences jedi-vim when dots are typed, while the second changes the default supertab setting (Tab = <Ctrl-(something)>) to instead be context aware and use the jedivim supported omnicomplete (see more details here: https://vi.stackexchange.com/questions/5416/cant-get-jedis-autocompletion-on-supertab)

Some additional notes on configuration: this setup is also preferable because I find jedi-vim to be quite slow in some cases. It appears this can be due to interactions with other packages, but this does not seem to be the case here (I don't have python-mode). Additionally, I can't get the inline function-signature to work because on MacOSX vim is compiled with -conceal. It's possible we can fix this by using macvim (which has +conceal?), but since the function signature is at the top of the documentation in most cases this is not an issue for me now.

Other new features

The jedi-vim package comes with a bunch of other new features that are worth documenting here too. Many of them are improvements upon vim-native features, and have corresponding key bindings, prepended with the

key, which in our case (by default) is the escape slash, ().
  • Go To Command: <leader>d Just like d in vim, will try to go to the first definition of the variable. Unlike vim, this command considers both assignments (in the current file), and definitions (in the current file or in any other file). It is also smart and will not jump to the first assignment counting by line if a variable is declared and then reassigned later.
  • Go To Assignments: <leader>g As above, but restricted to the file you're currently in.
  • Go To Stubs: <leader>s As above, but go to the stub.
  • Show documentation: <K> Shows documentation for the object under the cursor.
  • Rename: <leader>r Like vim r command, but will rename all instances of a variable with the same name simultanously! Very useful.
  • Show Usages: <leader>n Show all points where the current name is used in a quickfix window (type :cclose to close)
  • Explore module: :Pyimport {module name} Read through the code of an importable module in vim.

Clone this wiki locally