loading...
Cover image for Editor Wars: VIM as a perfect Python IDE

Editor Wars: VIM as a perfect Python IDE

bezirganyan profile image Grigor Bezirganyan ・4 min read

Backstory

Nowadays, there are many text editors and IDEs present for developers and it is often a hard decision to choose a particular one. Since most of them offer quite similar interface and functionality, it doesn’t really matter what editor will a beginner developer use. Nevertheless, for an intermediate or advanced developer choosing the right editor can give a significant performance boost.

There are many modern and powerful editors and IDEs, such as JetBrains IDEs, Visual Studio Code, Atom, etc. Nevertheless I would like to concentrate on one of the relatively old text editors, which can be as powerful (or more powerful :) ) as the other text editors, while, giving you a better typing experience. If you haven’t guessed it, I am talking about vim: a text editor released in 1991, which is still very popular. Although vim isn’t very beginner-friendly and isn’t as powerful out-of-the-box as other IDEs, with several plug-ins and configurations it can give you a better performance than your standard IDE.

In my previous post I talked about configuring VIM to compete with other IDEs. It was more C/C++ oriented, as that time my main language of coding was C++. A year ago, I changed my workplace and Python became my main programming language. Since almost everyone was using PyCharm at my workplace for Python development, I decided to give it a shot. I have to admit, PyCharm is a really good IDE and I enjoyed it’s smart functionality. Nevertheless I missed my typing experience in VIM. Installing vim layout for PyCharm didn’t rally help as well, and I decided to spend a day and configure my vim to have all the functionalities of PyCharm that I really needed.

Now let’s go to some of the features I managed to bring to VIM that made not to miss the PyCharm IDE.

Note that the plugins mentioned here are not python specific, but since I have mostly tested them on python, I cannot say for sure how they will work on other languages. If you have tested them it would be interesting to hear about your experience in the comment section:

Configuration

Code Completion

Code Completion

In my previous post I talked about YouCompleteMe, which is an awesome and open-source plug-in that offers a very good code suggestion for many languages. It was one of the best plug-ins I found while I was developing in C++, nevertheless, for Python I found a better alternative. Kite claims to use Machine Learning to offer useful code completion. Since Kite is closed-source we can not be really sure whether they really use Machine Learning or not, but I can guarantee that you will like it’s code suggestion.

One of the disadvantages of Kite is the fact that it is closed-source, and if you are a sworn open-source person, YouCompleteMe is still a pretty good option.

Error Detection

For syntax checking and error detection I use the ALE (Asynchronous Lint Engine) plug-in, which allows you to check your syntax while you type. It uses

ALE makes use of NeoVim and Vim 8 job control functions and timers to run linters on the contents of text buffers and return errors as text is changed in Vim. This allows for displaying warnings and errors in files being edited in Vim before files have been saved back to a filesystem

Furthermore, after some configurations ALE can check whether the python code is PEP-8 compliant and fixes it if it is not.

Navigation

Fast and effective navigation across files is an essential feature for fast development. One of the well known plug-ins for navigation in vim is the NERD Tree. Nevertheless I found the vim-vinegar to be a better alternative. It offers a cleaner interface and better shortcuts for navigation.

vinegar

crtl-p is another useful plug-in for easy navigation in vim. It is a

Full path fuzzy file, buffer, mru, tag, ... finder for Vim.

  • Written in pure Vimscript for MacVim, gVim and Vim 7.0+.
  • Full support for Vim's regexp as search patterns.
  • Built-in Most Recently Used (MRU) files monitoring.
  • Built-in project's root finder.
  • Open multiple files at once.
  • Create new files and directories.
  • Extensible.

ctrl-p

tmux

Although tmux is not a vim plug-in, it really improves the experience while coding in vim. Not only I can ssh to my machine anytime I want from anywhere in the world and get my session and layout, but it also takes my multitasking ability to a whole level.

tmux

Other plugins?

As I mentioned in my previous post there is a very awesome website full of various vim plugins, called vimawesome.com. You can find many many more plugins there and make your vim much closer to an actual IDE.

You can comment about your vim configuration below. By the way this is my first blog post, so I am waiting for your positive criticism in the comment section.

Posted on by:

Discussion

pic
Editor guide
 

Yo !

Like the setup, wish to know what debugger you're using and if you could write a lil' about it's setup.
Have you tested out LSP for python in vim? If so what are your thoughts?
I personally found pyls to be lacking autocomplete functionality but for C/C++ It proved better results than YCM.

 

Hey, thanks for the feedback!

Actually the debugging is one of the things I miss from PyCharm. I usually use debugger only when I feel that debugging with printing (logging in python) will not help me or will take more time (While coding in C++ I used debugger a lot, and had GDB integrated in vim with ConqueGDB Plugin). Sometimes when I really need a debugger I open PyCharm, debug and go back to vim :). Nevertheless, I am going to give vimpdb a try, will write about it if it proves itself useful.

No, I haven't tested LSP, my autocomplete path was this way:

  • Used YCM
  • Found Kite, started to use Kite for personal projects (since it was closed source and probably uploaded my code to their servers I couldn't use it in workplace's machine)
  • Finally went back to YCM, on my machine too
  • Learned that Kite now does the processing on local machine, but still it is closed source, you can never learn :D

Actually I will try LSP now, and see how it works for me!

 

Thanks for the response :)
I’m still a student so in the mean time it doesn’t bother me using kite even though it’s a lil’ unsafe. I didn’t try YCM with python, what are your thoughts about it compared to kite ?

As for the debugger, It’s a lil’ annoying to hit 2 keys instead of 1 compared to PyCharm using the standard pdb. Vimpdb seems a better way to integrate it with my workflow but based on the documentation, it won’t support python 3.0 +, only 2.4-2.7.
Please prove me wrong haha..

Nvim terminal is a bit buggy for me, so I’ll
test out ConqueGBD.. Demo looks good, hope you can customize it (color wise :p)

PS: Wish to find some more vim buddies as nobody in my college even heard of vim, nor wishes to learn about it unfortunately.. Didn’t find a way to contact you privately though.

Kite was pretty good for me, nevertheless, I have seen reviews that since it works locally now (or so they say :) ), it became worse. YCM is pretty good. The difference is that Kite uses ML to make suggestions. For example when you type import numpy, it will suggest as np as continuation. Not smth necessary but pretty cool :D

Actually, I have in mind to build smth like Kite but completely open-source (If I find time of course) :D I think LSTM will do the job :)

Ah Yeah, I missed that part about python 3. Guess I will not try it then :D Will search for alternatives, or stick to logging and occasionally PyCharming.
Keep me informed if you find something cool.

I used ConqueGBD really much when I was working on C++ projects. It is really good. Actually I believe there is a way to make GDB work for python as well. Will need some tweaking though. If I remember correctly (I used it last around 2 years ago) it picks your color scheme colors.

 

Thanks for the nice article. Just a suggestion. I think most of this is available by default in Spacevim. And for sure this is all available in Spacemacs with just the C and python layers . In my opinion these are very good starter (and expert) distributions. Also in my opinion, despite a few little downsides, Spacemacs is a better vim than (Space)vim itself and has many upsides compared to vim (especially the easier hackability due to the describe functionality). Of course you might call this opinion subjective, but you can not blame me for not mentioning it. Anyway, I recommend anyone (beginner and experts) to check these out... both a breeze to install

 

Hi,

Could you give your list of plugins or even create guide how to setup vim the way you did.

Looks awesome!

 

Hi, I am glad you liked my vim setup :D Yes, I have plans to write a blog post about, but I am not sure whether the time will allow me to do so in near future. In the meanwhile I will give you the list of plugins I use. I hope it will be helpful for you.

" Plugins
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-scripts/Conque-GDB'
Plugin 'ciaranm/detectindent'
Plugin 'bling/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'tpope/vim-fugitive'
Plugin 'arcticicestudio/nord-vim'
Plugin 'AutoClose'
Plugin 'vim-scripts/indentpython.vim'
Plugin 'kien/ctrlp.vim'
Plugin 'hynek/vim-python-pep8-indent'
Plugin 'w0rp/ale'
Plugin 'tpope/vim-vinegar'
Plugin 'tpope/vim-commentary'
Plugin 'vim-python/python-syntax'

And also, don't forget about kite :D

 

Thanks a lot :).

Looking forward to your setup guide if you catch some time.

Cheers.