Enabling Python Autocomplete in VIM on Raspberry Pi


This post shows steps to enable Python autocomplete in vim editor [1] on Raspberry Pi.

In this post, jedi-vim [2] and Vundle.vim [3] will be used for autocomplete plugin and plugin manager respectively. Also, even Raspbian Stretch has vim preinstalled, it’s a minimal version which is called “vim.tiny” and to use the plugin, we need to install another version of vim.

 

Prerequisites (parentheses indicate tested setup)

 

Steps
1. Install VIM
As mentioned above, another version of vim than the preinstalled one needs to be installed.

1-1. Update the package list.

sudo apt-get update

1-2. Install vim-nox.

sudo apt-get install vim-nox -y

 

2. Setup VIM
2-1. Clone VundleVim plugin.

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

2-2. Create a vim configuration file with vim.

vim ~/.vimrc

2-3. Activate the paste mode by the command below.

:set paste

2-4. Type “i” to go insert mode. Make sure that the paste mode is on as below.

-- INSERT (paste) --

2-5. Copy and paste the lines from line 1 to line 10 below.
Note: The lines after line 13 are my preferred settings and just for my reference. 

set nocompatible                  " be iMproved, required
filetype off                      " required
set rtp+=~/.vim/bundle/Vundle.vim " set the runtime path to include Vundle and initialize 
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'     " let Vundle manage Vundle, required
Plugin 'davidhalter/jedi-vim'     " jedi-vim

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

" Put your non-Plugin stuff after this line
colo murphy      " set colorscheme 
syntax enable    " enable syntax highlighting 
set number       " show line numbers 
set mouse=a      " turn on xterm style mousing which allows to select text w/o line numbers 
set clipboard=unnamedplus " copy yanked text to system clipboard 
set ts=4         " set tabs to have 4 spaces
set autoindent   " indent when moving to the next line while writing code 
set expandtab    " expand tabs into spaces 
set shiftwidth=4 " when using the >> or << commands, shift lines by 4 spaces 
set cursorline   " show a visual line under the cursor's current line 
set showmatch    " show the matching part of the pair for [] {} and () 
set laststatus=2 " display file name on the bottom bar
set pastetoggle=<F3> "paste mode toggling
let python_highlight_all = 1 " enable all Python syntax highlighting features
highlight OverLength ctermbg=red ctermfg=white guibg=#592929
match OverLength /\%81v.\+/

2-6. Exit the insert mode by pressing “Ctrl” + “[“.

2-7. Save the file by typing “:w” and enter.

:w

2-8. Execute the file by the command below.

:source %

2-9. Install the plugins by entering the command below.

:PluginInstall

It will show “Processing” in the status bar. It takes a while.

2-10. When the status bar shows “Done!”, close the file by entering “:q”.

 

3. Verify Autocomplete

 

References
[1] Vim – the ubiquitous text editor
[2] jedi-vim – awesome Python autocompletion with VIM – GitHub
[3] Vundle.vim – GitHub
[4] jedi-vim – Vim Awesome
[5] VIM and Python – A Match Made in Heaven

 

 

Sponsor Link

2 Comments

  1. Well done!

    Thanks for the explanation and well commented .vimrc.
    Every little bit helps.

Comments are closed.