| 1 |
.. image:: https://github.com/davidhalter/jedi-vim/blob/master/doc/logotype-a.svg |
| 2 |
|
| 3 |
################################################# |
| 4 |
jedi-vim - awesome Python autocompletion with VIM |
| 5 |
################################################# |
| 6 |
|
| 7 |
.. image:: https://travis-ci.org/davidhalter/jedi-vim.svg?branch=master |
| 8 |
:target: https://travis-ci.org/davidhalter/jedi-vim |
| 9 |
:alt: Travis-CI build status |
| 10 |
|
| 11 |
jedi-vim is a VIM binding to the autocompletion library |
| 12 |
`Jedi <http://github.com/davidhalter/jedi>`_. |
| 13 |
|
| 14 |
Here are some pictures: |
| 15 |
|
| 16 |
.. image:: https://github.com/davidhalter/jedi/raw/master/docs/_screenshots/screenshot_complete.png |
| 17 |
|
| 18 |
Completion for almost anything (Ctrl+Space). |
| 19 |
|
| 20 |
.. image:: https://github.com/davidhalter/jedi/raw/master/docs/_screenshots/screenshot_function.png |
| 21 |
|
| 22 |
Display of function/class bodies, docstrings. |
| 23 |
|
| 24 |
.. image:: https://github.com/davidhalter/jedi/raw/master/docs/_screenshots/screenshot_pydoc.png |
| 25 |
|
| 26 |
Documentation (Pydoc) support (with highlighting, Shift+k). |
| 27 |
|
| 28 |
There is also support for goto and renaming. |
| 29 |
|
| 30 |
|
| 31 |
Get the latest from `github <http://github.com/davidhalter/jedi-vim>`_. |
| 32 |
|
| 33 |
Documentation |
| 34 |
============= |
| 35 |
|
| 36 |
Documentation is available in your vim: ``:help jedi-vim``. You can also look |
| 37 |
it up `on github <http://github.com/davidhalter/jedi-vim/blob/master/doc/jedi-vim.txt>`_. |
| 38 |
|
| 39 |
You can read the Jedi library documentation `here <http://jedi.readthedocs.io/en/latest/>`_. |
| 40 |
|
| 41 |
If you want to report issues, just use the github issue tracker. In case of |
| 42 |
questions about the software, please use `stackoverflow |
| 43 |
<https://stackoverflow.com/questions/tagged/jedi-vim>`_ and tag your question with ``jedi-vim``. |
| 44 |
|
| 45 |
|
| 46 |
Contributing |
| 47 |
============ |
| 48 |
|
| 49 |
We love Pull Requests! Read the instructions in ``CONTRIBUTING.md``. |
| 50 |
|
| 51 |
|
| 52 |
Features |
| 53 |
======== |
| 54 |
|
| 55 |
The Jedi library understands most of Python's core features. From decorators to |
| 56 |
generators, there is broad support. |
| 57 |
|
| 58 |
Apart from that, jedi-vim supports the following commands |
| 59 |
|
| 60 |
- Completion ``<C-Space>`` |
| 61 |
- Goto assignment ``<leader>g`` (typical goto function) |
| 62 |
- Goto definition ``<leader>d`` (follow identifier as far as possible, |
| 63 |
includes imports and statements) |
| 64 |
- Goto (typing) stub ``<leader>s`` |
| 65 |
- Show Documentation/Pydoc ``K`` (shows a popup with assignments) |
| 66 |
- Renaming ``<leader>r`` |
| 67 |
- Usages ``<leader>n`` (shows all the usages of a name) |
| 68 |
- Open module, e.g. ``:Pyimport os`` (opens the ``os`` module) |
| 69 |
|
| 70 |
|
| 71 |
Installation |
| 72 |
============ |
| 73 |
|
| 74 |
Requirements |
| 75 |
------------ |
| 76 |
- **Vim**: You need a VIM version that was compiled with Python 3 or later |
| 77 |
(``+python3``). You can check this from within VIM using |
| 78 |
``:python3 import sys; print(sys.version)``. |
| 79 |
|
| 80 |
- **Neovim**: You need a python environment with ``pynvim`` installed: |
| 81 |
``pip install pynvim`` |
| 82 |
|
| 83 |
then check your environment is correctly setup from within Neovim using |
| 84 |
``:checkhealth provider.python`` |
| 85 |
|
| 86 |
Manual installation |
| 87 |
------------------- |
| 88 |
|
| 89 |
You might want to use `pathogen <https://github.com/tpope/vim-pathogen>`_ or |
| 90 |
`Vundle <https://github.com/gmarik/vundle>`_ to install jedi-vim. |
| 91 |
|
| 92 |
The first thing you need after that is an up-to-date version of Jedi. Install |
| 93 |
``git submodule update --init --recursive`` in your jedi-vim repository. |
| 94 |
|
| 95 |
Example installation command using Pathogen: |
| 96 |
|
| 97 |
.. code-block:: sh |
| 98 |
|
| 99 |
git clone --recursive https://github.com/davidhalter/jedi-vim.git ~/.vim/bundle/jedi-vim |
| 100 |
|
| 101 |
Example installation using Vundle: |
| 102 |
|
| 103 |
Add the following line in your `~/.vimrc` |
| 104 |
|
| 105 |
.. code-block:: vim |
| 106 |
|
| 107 |
Plugin 'davidhalter/jedi-vim' |
| 108 |
|
| 109 |
For installing Jedi, ``pip install jedi`` will also work, but you might run |
| 110 |
into issues when working in virtual environments. Please use git submodules. |
| 111 |
|
| 112 |
|
| 113 |
Installation with your distribution |
| 114 |
----------------------------------- |
| 115 |
|
| 116 |
On Arch Linux, you can also install jedi-vim from official repositories as |
| 117 |
`vim-jedi <https://archlinux.org/packages/extra/any/vim-jedi/>`__. |
| 118 |
It is also available on |
| 119 |
`Debian (≥8) <https://packages.debian.org/vim-python-jedi>`__ and |
| 120 |
`Ubuntu (≥14.04) <http://packages.ubuntu.com/vim-python-jedi>`__ as |
| 121 |
vim-python-jedi. |
| 122 |
On Fedora Linux, it is available as |
| 123 |
`vim-jedi <https://packages.fedoraproject.org/pkgs/vim-jedi/vim-jedi/>`__. |
| 124 |
|
| 125 |
Please note that this version might be quite old compared to using jedi-vim |
| 126 |
from Git. |
| 127 |
|
| 128 |
Caveats |
| 129 |
------- |
| 130 |
|
| 131 |
Note that the `python-mode <https://github.com/klen/python-mode>`_ VIM plugin seems |
| 132 |
to conflict with jedi-vim, therefore you should disable it before enabling |
| 133 |
jedi-vim. |
| 134 |
|
| 135 |
To enjoy the full features of jedi-vim, you should have VIM >= 7.3, compiled with |
| 136 |
``+conceal`` (which is not the case on some platforms, including OS X). If your VIM |
| 137 |
does not meet these requirements, the parameter recommendation list may not appear |
| 138 |
when you type an open bracket after a function name. Please read |
| 139 |
`the documentation <http://github.com/davidhalter/jedi-vim/blob/master/doc/jedi-vim.txt>`_ |
| 140 |
for details. |
| 141 |
|
| 142 |
|
| 143 |
Settings |
| 144 |
======== |
| 145 |
|
| 146 |
Jedi is by default automatically initialized. If you don't want that I suggest |
| 147 |
you disable the auto-initialization in your ``.vimrc``: |
| 148 |
|
| 149 |
.. code-block:: vim |
| 150 |
|
| 151 |
let g:jedi#auto_initialization = 0 |
| 152 |
|
| 153 |
There are also some VIM options (like ``completeopt`` and key defaults) which |
| 154 |
are automatically initialized, but you can skip this: |
| 155 |
|
| 156 |
.. code-block:: vim |
| 157 |
|
| 158 |
let g:jedi#auto_vim_configuration = 0 |
| 159 |
|
| 160 |
|
| 161 |
You can make jedi-vim use tabs when going to a definition etc: |
| 162 |
|
| 163 |
.. code-block:: vim |
| 164 |
|
| 165 |
let g:jedi#use_tabs_not_buffers = 1 |
| 166 |
|
| 167 |
If you are a person who likes to use VIM-splits, you might want to put this in your ``.vimrc``: |
| 168 |
|
| 169 |
.. code-block:: vim |
| 170 |
|
| 171 |
let g:jedi#use_splits_not_buffers = "left" |
| 172 |
|
| 173 |
This options could be "left", "right", "top", "bottom" or "winwidth". It will decide the direction where the split open. |
| 174 |
|
| 175 |
Jedi automatically starts the completion, if you type a dot, e.g. ``str.``, if |
| 176 |
you don't want this: |
| 177 |
|
| 178 |
.. code-block:: vim |
| 179 |
|
| 180 |
let g:jedi#popup_on_dot = 0 |
| 181 |
|
| 182 |
Jedi selects the first line of the completion menu: for a better typing-flow |
| 183 |
and usually saves one keypress. |
| 184 |
|
| 185 |
.. code-block:: vim |
| 186 |
|
| 187 |
let g:jedi#popup_select_first = 0 |
| 188 |
|
| 189 |
Jedi displays function call signatures in insert mode in real-time, highlighting |
| 190 |
the current argument. The call signatures can be displayed as a pop-up in the |
| 191 |
buffer (set to 1 by default (with the conceal feature), 2 otherwise), |
| 192 |
which has the advantage of being easier to refer to (but is a hack with |
| 193 |
many drawbacks since it changes the buffer's contents), |
| 194 |
or in Vim's command line aligned with the function call (set to 2), which |
| 195 |
can improve the integrity of Vim's undo history. |
| 196 |
|
| 197 |
.. code-block:: vim |
| 198 |
|
| 199 |
let g:jedi#show_call_signatures = "1" |
| 200 |
|
| 201 |
Here are a few more defaults for actions, read the docs (``:help jedi-vim``) to |
| 202 |
get more information. If you set them to ``""``, they are not assigned. |
| 203 |
|
| 204 |
.. code-block:: vim |
| 205 |
|
| 206 |
NOTE: subject to change! |
| 207 |
|
| 208 |
let g:jedi#goto_command = "<leader>d" |
| 209 |
let g:jedi#goto_assignments_command = "<leader>g" |
| 210 |
let g:jedi#goto_stubs_command = "<leader>s" |
| 211 |
let g:jedi#goto_definitions_command = "" |
| 212 |
let g:jedi#documentation_command = "K" |
| 213 |
let g:jedi#usages_command = "<leader>n" |
| 214 |
let g:jedi#completions_command = "<C-Space>" |
| 215 |
let g:jedi#rename_command = "<leader>r" |
| 216 |
let g:jedi#rename_command_keep_name = "<leader>R" |
| 217 |
|
| 218 |
An example for setting up your project: |
| 219 |
|
| 220 |
.. code-block:: vim |
| 221 |
|
| 222 |
let g:jedi#environment_path = "/usr/bin/python3.9" |
| 223 |
|
| 224 |
jedi-vim tries its best to guess your virtual env. If you want to work with a |
| 225 |
specific virtual environment however, you can point jedi-vim towards it: |
| 226 |
|
| 227 |
.. code-block:: vim |
| 228 |
|
| 229 |
let g:jedi#environment_path = "venv" |
| 230 |
|
| 231 |
Finally, if you don't want completion, but all the other features, use: |
| 232 |
|
| 233 |
.. code-block:: vim |
| 234 |
|
| 235 |
let g:jedi#completions_enabled = 0 |
| 236 |
|
| 237 |
FAQ |
| 238 |
=== |
| 239 |
|
| 240 |
I want to use Jedi with a Python 2 Environment, but it's not listed under "Known environments" |
| 241 |
---------------------------------------------------------------------------------------------- |
| 242 |
|
| 243 |
Starting with version 0.18.0 Jedi dropped support for Python 2. |
| 244 |
|
| 245 |
|
| 246 |
I don't want the docstring window to popup during completion |
| 247 |
------------------------------------------------------------ |
| 248 |
|
| 249 |
This depends on the ``completeopt`` option. Jedi initializes it in its |
| 250 |
``ftplugin``. Add the following line to your ``.vimrc`` to disable it: |
| 251 |
|
| 252 |
.. code-block:: vim |
| 253 |
|
| 254 |
autocmd FileType python setlocal completeopt-=preview |
| 255 |
|
| 256 |
|
| 257 |
I want <Tab> to do autocompletion |
| 258 |
--------------------------------- |
| 259 |
|
| 260 |
Don't even think about changing the Jedi command to ``<Tab>``, |
| 261 |
use `supertab <https://github.com/ervandew/supertab>`_! |
| 262 |
|
| 263 |
|
| 264 |
The completion is too slow! |
| 265 |
--------------------------- |
| 266 |
|
| 267 |
1. Completion of complex libraries (like Numpy) should only be slow the first |
| 268 |
time you complete them. After that the results should be cached and very fast. |
| 269 |
|
| 270 |
2. If it is still slow after the initial completion and you have installed the |
| 271 |
python-mode Vim plugin, try disabling its rope mode: |
| 272 |
|
| 273 |
.. code-block:: vim |
| 274 |
|
| 275 |
let g:pymode_rope = 0 |
| 276 |
|
| 277 |
See issue `#163 <https://github.com/davidhalter/jedi-vim/issues/163>`__. |
| 278 |
|
| 279 |
3. You can also use `deoplete-jedi <https://github.com/zchee/deoplete-jedi>`__ |
| 280 |
for completions, which uses Jedi, but does completions asynchronously |
| 281 |
(requires Neovim). |
| 282 |
It makes sense to use both jedi-vim and deoplete-jedi, but you should disable |
| 283 |
jedi-vim's completions then: |
| 284 |
|
| 285 |
.. code-block:: vim |
| 286 |
|
| 287 |
let g:jedi#completions_enabled = 0 |
| 288 |
|
| 289 |
Testing |
| 290 |
======= |
| 291 |
|
| 292 |
jedi-vim is being tested with a combination of `vspec |
| 293 |
<https://github.com/kana/vim-vspec>`_ and `py.test <http://pytest.org/>`_. |
| 294 |
|
| 295 |
The tests are in the ``test`` subdirectory, you can run them calling:: |
| 296 |
|
| 297 |
py.test |
| 298 |
|
| 299 |
The tests are automatically run with `travis |
| 300 |
<https://travis-ci.org/davidhalter/jedi-vim>`_. |