Vim plugin for Python 3+ 🐍 written in Python 3+ 🐍 for project specific autocomplete and search of functions and classes and automatic import filling
The current state of vim-python-domain-knowledge
has 3 responsibilities:
- Global "project specific" autocomplete for all classes and functions that are defined inside a given projects
More about this: here
NOTE: This plugin is not a replacement of jedi-vim. It provides a first-level autocomplete for everything inside the project (jedi provides detailed attributes specific autocomplete only for variables in the context)
-
Global search for all classes and functions in the projects using the vim embedded search regex matching
-
Automatically autofill the import for:
- every class that's defined inside the project (no matter in which file)
- every function that's defined inside the project (no matter in which file)
- every imported stuff (from any third party library inside the project)
More about this: here
A really common action in the python development is using functions that are not in the same file. The process usually looks like this:
- Start typing the name (probably forgot the exact name since is long and explicitly descriptive)
- Jump to the top of the file looking at the imports
- Remember the place where the function lives (probably grep inside the project)
- Find the right place in the imports to put the new function import
- Start typing by autosuggesting the name using the import location
- Jump back to the place where you want to use the function and autocomlete it
The aim of this plugin is to automate this process by generating knowledge for your existing codebase and use it to autosuggest the function/class/constant you want to use at the moment of typing + suggest the right import and put it at the right place.
Make sure you have installed Sqlite first!
Place this in your .vimrc
Plugin 'HackSoftware/vim-python-domain-knowledge'
… then run the following in Vim:
:source %
PluginInstall
Make sure you have installed Sqlite first!
Place this in your .vimrc
Plug 'HackSoftware/vim-python-domain-knowledge'
… then run the following in Vim:
:source %
PlugInstall
Make sure you have installed Sqlite first!
Run the following in a terminal:
cd ~/.vim/bundle
git clone https://github.com/HackSoftware/vim-python-domain-knowledge.git
IMPORTANT NOTE: The only external dependency of this plugin is SQLite3 (https://www.sqlite.org/index.html). Make sure you have it installed on your operating system :)
NOTE: this should be done only once for a project
cd /path/to/project
:call PythonDomainKnowledgeCollectImports()
NOTE: It could take a few seconds until it parse the whole project's Abstract syntax tree and extract the need. If everything is successfull you should see .vim_domain_knowledge/
folder inside you project
.vim_domain_knowledge/
" To map your shortcut for autofilling import for the word under the cursor
nnoremap <your_custom_mapping> :call PythonDomainKnowledgeFillImport()<CR>
" To map your shortcut for global searching
noremap <C-m> :call PythonDomainKnowledgeSearch()<Cr>
Sample configuration:
" This will autofill the import for the word under the cursor when you press F9 key (in normal mode) :)
nnoremap <F9> :call PythonDomainKnowledgeFillImport()<CR>
" This will open the search as soon as you press "ctrl + m" in normal mode
noremap <C-m> :call PythonDomainKnowledgeSearch()<Cr>
Start typing and press Ctrl + x
and then Ctrl + u
(while in insert mode)
NOTE: You can remap this ^ . It's the default vim shortcut for autocomplete from custom completefunc
In normal model run
:call PythonDomainKnowledgeSearch()
(or a keybinding for this)
Write the full name of the function/class you want to use. Then in normal mode run:
:call PythonDomainKnowledgeFillImport()
(or a keybinding for this)
Feedback is the best power for making things better. Any form of feedback is highly appreaciated:
- open an issue - for bug 🐛 or new feature proposal
- give a star ⭐
- contribute (fork the repo + open pull request)