Introduction to IDE

An IDE or integrated development environment refers to software that offers extensive software development features for python developers and programmers. Features like source code editor, debugger and intelligent code completion have made IDEs an integral tool for development. The use of a good IDE can increase the productivity of the programmers. Selecting an ideal IDE from a sea of IDEs available today can be very difficult for python developers but one great option can be Vim as Python IDE.

python CTA

In this article, we will explore vim as a python ide, how it can be the best option for python development, along with all the features and plugins it offers. The article also provides a step-by-step guide to turning Vim into an ideal IDE for python.

What is Vim?

Technically, Vim is not an IDE but a text editor, an extremely lightweight and highly extensible text editor. It is very easy to use and learn as it offers an excellent interface for navigating and editing text. It allows developers to add plugins of their choice by installing other packages so that They can be tailored as per their requirements. This way vim can be transformed into a Python IDE.

Vim as a python IDE

As mentioned earlier, it is a very fast and highly customizable IDE. Another reason to choose vim is the range of customizable keyboard shortcuts it offers. It can actually be configured in a way that it would not require you to even touch the mouse. As a result, it can significantly reduce your coding time but the Vim Plugins are what make Vim one of the best options for a python IDE. There are a variety of plugins available to achieve even the smallest features as per your requirements.

Transforming Vim as a Python IDE

This demonstration provides a step-by-step guide to using VIM as a python IDE

1. Installing Vim on your device

Vim installation is a very easy process across all operating systems. In macOS, you just need to use the following commands in Homebrew,

$ brew update

$ brew install vim

In Linux, (Debian or Ubuntu), you can use these commands,

$ sudo apt-get remove vim-tiny

$ sudo apt-get update

$ sudo apt-get install vim

While in Windows operating system, you will need to install Vim separately. Fortunately, Microsoft makes it very convenient to install Vim and get it running on your system. It can be easily installed by downloading the executable installer from their website.

Make sure you have installed VIM version 7.3 or greater with Python support. To check that, run the following command,

vim --version

You can check the specific version of Python used in VIM by,

:python import sys; print(sys.version)

This will output the current version of Python installed on your system. In case, if this gives you an error, it means you do not have Python support.

2. Installing Plugin Manager for Vim

Despite VIM being capable enough to be used for development out of the box. However, it is also extremely extensible, and as mentioned earlier there are tons of plugins available to turn it into a complete IDE. For that, the very first thing that is required is a plugin manager to install all plugins. Vim offers a native plugin manager along with several extension managers, but we will be using Vundle. Consider Vundle like pip for Vim, as it makes installing and updating packages way easier.

Vundle

To install Vundle on a Linux system, you need to run the following command:

$ git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

After that, add the file to your user’s home directory:

$ touch ~/.vimrc

These commands will download the Vundle plugin manager and add it to your VIM bundles directory. Now all the installed plugins can be managed from the .vimrc configuration file.

Now to set up Vundle in the .vimrc, you have to add the following lines to the top of the file:

set nocompatible " required
filetype off " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

" add all your plugins here (note older versions of Vundle
" used Bundle instead of Plugin)

" ...

" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required

To install Vundle on a windows system, you need to have Git and Curl installed on your system. After that, you can install Vundle from

https://github.com/VundleVim/Vundle.vim

All is done. Now you are all set up to use Vundle. Afterwards, you can install plugins as per your requirements. A major reason for using Vim was to be able to use the following command

:PluginInstall

This command allows you to automatically download and install all the plugins for you making things quite easy but if you want to customize Vim as per your preferences. The next sections discuss some very useful features offered by Vim.

Features and plugins by Vim

Vim offers a long list of features; some come built-in whereas the rest can be easily installed in form of a plugin. Following are some of the most common and very useful features that can be utilized to use Vim as Python IDE. The commands to install the plugins or configure the Vim are mentioned as well.

File Browsing in Vim

Most IDEs offer a sidebar that gives access to all of your project files. You can get the same feature in Vim using the plugin, NerdTree. This will place a file explorer inside your vim window that will allow you to visually browse your project directory.

Plugin 'scrooloose/nerdtree'

Syntax highlighting

The python-mode plugin offers multiple features but it is mostly used to add syntax highlighting features in Vim. Syntax highlighting can provide visual cues and keywords that make the code easier to read by visually clarifying the programming language syntax. It also offers to Add or remove breakpoints in your code. It also automatically Improves Python indentation and offers code refactoring.

Plugin ‘python-mode/pymode.vim’

Auto completion

The YouCompleteMe plugin can be used to add an auto-completion feature in Vim. YouCompleteMe plugin adds a very swift, as-you-type, fuzzy-search code completion to Vim. It is a bundle that offers more features and can be installed using Vundle.

Bundle 'Valloric/YouCompleteMe'

Syntax checking/lint

If you want to use lint, there is a plugin, ALE for that. ALE or Asynchronous Lint Engine plugin provides linting in Vim 8 while you edit your text files.

Plugin ‘dense-analysis/ale’

Tabs in Vim

If you are habitual of using Tabs in an IDE, Vim supports tabs out of the box. You can use the following commands to configure them.

To switch between the tabs:

:tabn and :tabp

To list all your tabs type:

:tabs

To close a tab:

:tabclose

To open a new tab with the file:

:tabedit file

Auto-Indentation

Auto indentation can be very helpful while coding in python and works quite well as well, but in certain cases like when a function signature goes up to multiple lines, it does not always intend the code correctly. The indentpython.vim plugin can be used to fix that issue but improve the auto-Indentations.

Plugin 'vim-scripts/indentpython.vim'

Git Integration

The vim-fugitive plugin allows you to perform basic git commands without even leaving the Vim terminal.

Plugin 'tpope/vim-fugitive'

Line Numbering

You can turn on the line numbers on the side of the screen using,

set nu

Powerline

Powerline is a status bar plugin that displays information such as the current virtual environment, git branch, files that are being edited etc in a status bar.

Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}

System Clipboard

Although Vim offers its clipboard it ignores the system shortcuts such as cut, copy, and/or paste to/from other applications outside of VIM. You can access your system clipboard using this command:

set clipboard=unnamed

Super Searching

You can search for basically anything on VIM by installing ctrlP plugin,

Plugin 'kien/ctrlp.vim'

After installation, Ctrl+P will enable the search. If your search matches anything it will find it and not just files but tags as well.

UTF-8 Support

For most of your coding, you would be using the UTF-8 when working with Python, especially when you are working with Python 3. To make sure that VIM knows about it use the following line:

set encoding=utf-8

Split Layouts

Vim allows splitting layouts by opening a file with these commands

To split the layout vertically

:sp <filename>

To split the layout horizontally

:vs <filename>

You can also nest splits by using these commands, as well, so you can have splits inside of splits, horizontal and vertical. After opening the files, the following commands can be used to change the split screen behavior while coding.

set splitbelow
set splitright

Wrapping it up

It is now evident that Vim as a python IDE can be a great option. Having a one-and-for-all IDE is not easy to find, but comes very close to that. The variety of all the available plugins and customizations can make your coding quite easier.

We have just explored the tip of the iceberg by coving a handful of plugins and settings. The purpose was to just to introduce the Vim plugins as now, you can explore the huge variety of plugins that are available for Vim to extensively customize it as per your coding requirements.

Also Read: The Best Ides For Reactive Native Apps – 5 Popular Examples

python CTA2

Author

Full Stack Java Developer | Writer | Recruiter, bridging the gap between exceptional talent and opportunities, for some of the biggest Fortune 500 companies.

Write A Comment