Python IDE with Neovim


Neovim is my favourite editor, so it was only natural for me to try and use it as my python IDE. Setting it up was not an easy task because I haven’t programmed in ages, neither do I have serious experience with Linux. Before I get into the nuts and the bolts let me tell you about my setup.

I use ArchLinux and I try to make it my daily driver, but it’s not easy because I work for a Microsoft shop. URXVT is my terminal emulator of choice and its housed in the I3 window manager.  I use the patched URXVT downloaded from the AUR (You don’t have to go for the patched version. I got it because I thought it would help me to use the Powerline fonts and symbols in Neovim. I still haven’t got that to work.). I also got Neovim from the Arch repository.

The four things in an IDE that I was looking for was Autocompletion, Linting, Code Execution and Repository integration. With the right plugins, NVIM does all that for you.

 My setup is heavily based on this excellent article written by Yufanlu. Might I suggest that you head over to his site to get your setup, up and running because I don’t think that I can give you better instructions. But, before you go, I have a few suggestions for you, if you are a naive user.

Do not use the Arch repository to install anything related to configuring NVIM, Use PIP2 or PIP3 instead. If you have stuff from Arch, uninstall it. It just didn’t work for me.  I tried using Pymode and YCM but it just didn’t float my boat. Pymode was slow, and its configuration was a bit cumbersome. YCM, on the other hand, was like a bulldozer. I needed something light and small. YCM also requires you to RTFM. Not my forte. I gave up on powerline, devicons etc because I failed to get it configured on Nvim. Anyway, I ended up using NCM2 and it seems to work without a glitch. Never got a chance to check out Deoplete. I got rid of rope because it was slow.

If you are interested in my vimrc file, it’s on git. It’s well commented so you might learn a thing or two. All of the python plugins were downloaded using sudo PIP Install plugin or pip install –user plugin

F3 – auto-formats the code

F1 – run’s the python code.

GoTo – <Leader>d

GoTo Assignments – <Leader>g

Documentation – K

Completions – <C-Space> (faster)

rename – <Leader>r

Dot completion is automatic 

Linting is done during writes.

I didn’t do any repository integration.

Image taken using scrot. scrot -t 20 -d 5  ## 20% size 5 seconds later 

Note: A word on auto-completion or code completion

Since python is a dynamically typed language, you will notice that code completion does not always work automagically. But you can make that happen by providing type annotations or hints.  To make this happen, install “Typing” using PIP3 or PIP. Then, in your code do likewise

import pandas as pd
import typing
melb_data = pd.read_csv("Some_file") # type: pd.DataFrame
# It might help to save your code now
# Jedi happily completes the dropna() with out typings
melb_data = melb_data.dropna()
# But it does not acknowledge .select_dtypes() unless you type the data
melb_data = melb_data.select_dtypes()


The secret sauce was to import typing and add an annotation to the data type. With that in place, Jedi knows your data type. I should mention that there was a slight delay (4-8 sec) for the auto-completion to pop up

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s