How to Set Up VIM Editor for Python Programming
How to Set Up VIM Editor for Python Programming
VIM is a customizable programmable text editor. You can do anything you want with VIM if you know how VIM works and how to write VIM plugins. It is so simple to set up VIM Editor for Python Programming and this tutorial covers the ground on the same process.
Installing VIM
First, update the package repository cache with the following command.
root@linuxhelp:~# apt-get update
Ign:1 cdrom://Ubuntu 17.04 _Zesty Zapus_ - Release amd64 (20170412) zesty InRelease
Hit:2 cdrom://Ubuntu 17.04 _Zesty Zapus_ - Release amd64 (20170412) zesty Release
Hit:4 http://old-releases.ubuntu.com/ubuntu zesty InRelease
Hit:5 http://archive.canonical.com/ubuntu zesty InRelease
Hit:6 http://old-releases.ubuntu.com/ubuntu zesty-updates InRelease
Hit:7 http://old-releases.ubuntu.com/ubuntu zesty-security InRelease
Hit:8 http://ppa.launchpad.net/pmjdebruijn/darktable-release/ubuntu zesty InRelease
Reading package lists... Done
And then the VIM should be installed by making use of the following command.
root@linuxhelp:/var/lib/dpkg# apt install vim
Reading package lists... Done
Building dependency tree
Reading state information... Done
You can now run VIM with the following command:
.
.
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto mode
Once it is done, you need to configure VIM for Python. Make use of the following command to open the file.
root@linuxhelp:~# vim ~/.vimrc
In that file you need to type the following lines.
syntax enable set tabstop=4 set shiftwidth=4 set expandtab set number filetype indent on set autoindent
Save and exit it, once you are done.
You can see how it looks by making use of the following command.
root@linuxhelp:~# vim ~/.vimrc
1 syntax enable
2 set tabstop=4
3 set shiftwidth=4
4 set expandtab
5 set number
6 filetype indent on
7 set autoindent
~
: wq
Now we install python-syntax (https://github.com/hdima/python-syntax), a syntax highlighting module on VIM for better python syntax highlighting of Python2 and Python3. The python-syntax module must be kept on a specific directory ‘ ~/.vim/syntax’ for it to work. Do as follows.
root@linuxhelp:~# mkdir -p ~/.vim/syntax
root@linuxhelp:~# cd ~/.vim/syntax
Now download Python-syntax module with ‘ wget’ command like given in the following manner.
root@linuxhelp:~# wget https://raw.githubusercontent.com/hdima/python-syntax/master/syntax/python.vim
Now again open the configuration file that you edited previously.
root@linuxhelp:~/.vim/syntax# vim ~/.vimrc
And add the 9th line to enable python-syntax module.
1 syntax enable 2 set tabstop=4 3 set shiftwidth=4 4 set expandtab 5 set number 6 filetype indent on 7 set autoindent 8 9 let python-highlight_all = 1 ~
Now save the file.
This is how you configure VIM for Python.
Comments ( 0 )
No comments available