jedi-vim.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. *jedi-vim.txt* - For Vim version 7.3 - Last change: 2014/07/29
  2. __ _______ _______ __ ____ ____ __ .___ ___.~
  3. | | | ____|| \ | | \ \ / / | | | \/ |~
  4. | | | |__ | .--. || | _____\ \/ / | | | \ / |~
  5. .--. | | | __| | | | || | |______\ / | | | |\/| |~
  6. | `--' | | |____ | '--' || | \ / | | | | | |~
  7. \______/ |_______||_______/ |__| \__/ |__| |__| |__|~
  8. jedi-vim - awesome Python autocompletion with Vim
  9. ==============================================================================
  10. Contents *jedi-vim-contents*
  11. 1. Introduction |jedi-vim-introduction|
  12. 2. Installation |jedi-vim-installation|
  13. 2.0. Requirements |jedi-vim-installation-requirements|
  14. 2.1. Manually |jedi-vim-installation-manually|
  15. 2.2. Using Pathogen |jedi-vim-installation-pathogen|
  16. 2.3. Using Vundle |jedi-vim-installation-vundle|
  17. 2.4. Installing from Repositories |jedi-vim-installation-repos|
  18. 3. Supported Python features |jedi-vim-support|
  19. 4. Usage |jedi-vim-usage|
  20. 5. Mappings |jedi-vim-keybindings|
  21. 5.1. Start completion |g:jedi#completions_command|
  22. 5.2. Go to assignment |g:jedi#goto_assignments_command|
  23. 5.3. Get original definition |g:jedi#goto_definitions_command|
  24. 5.4. Show documentation |g:jedi#documentation_command|
  25. 5.5. Rename variables |g:jedi#rename_command|
  26. 5.6. Show name usages |g:jedi#usages_command|
  27. 5.7. Open module by name |:Pyimport|
  28. 6. Configuration |jedi-vim-configuration|
  29. 6.1. auto_initialization |g:jedi#auto_initialization|
  30. 6.2. auto_vim_configuration |g:jedi#auto_vim_configuration|
  31. 6.3. popup_on_dot |g:jedi#popup_on_dot|
  32. 6.4. popup_select_first |g:jedi#popup_select_first|
  33. 6.5. auto_close_doc |g:jedi#auto_close_doc|
  34. 6.6. show_call_signatures |g:jedi#show_call_signatures|
  35. 6.7. use_tabs_not_buffers |g:jedi#use_tabs_not_buffers|
  36. 6.8. squelch_py_warning |g:jedi#squelch_py_warning|
  37. 6.9. completions_enabled |g:jedi#completions_enabled|
  38. 6.10. use_splits_not_buffers |g:jedi#use_splits_not_buffers|
  39. 6.11. force_py_version |g:jedi#force_py_version|
  40. 7. Testing |jedi-vim-testing|
  41. 8. Contributing |jedi-vim-contributing|
  42. 9. License |jedi-vim-license|
  43. ==============================================================================
  44. 1. Introduction *jedi-vim-introduction*
  45. Jedi-vim is a Vim binding to the awesome Python autocompletion library
  46. `jedi`. Among jedi's (and, therefore, jedi-vim's) features are:
  47. - Completion for a wide array of Python features (see |jedi-vim-support|)
  48. - Robust in dealing with syntax errors and wrong indentation
  49. - Parses complex module/function/class structures
  50. - Infers function arguments from Sphinx/Epydoc strings
  51. - Doesn't execute Python code
  52. - Supports Virtualenv
  53. - Supports Python 2.5+ and 3.2+
  54. By leveraging this library, jedi-vim adds the following capabilities to Vim:
  55. - Displaying function/class bodies
  56. - "Go to definition" command
  57. - Displaying docstrings
  58. - Renaming and refactoring
  59. - Looking up related names
  60. ==============================================================================
  61. 2. Installation *jedi-vim-installation*
  62. ------------------------------------------------------------------------------
  63. 2.0. Requirements *jedi-vim-installation-requirements*
  64. First of all, jedi-vim requires Vim to be compiled with the `+python` option.
  65. The jedi library has to be installed for jedi-vim to work properly. You can
  66. install it first, by using e.g. your distribution's package manager, or by
  67. using pip: >
  68. pip install jedi
  69. However, you can also install it as a git submodule if you don't want to use
  70. jedi for anything but this plugin. How to do this is detailed below.
  71. It is best if you have VIM >= 7.3, compiled with the `+conceal` option. With
  72. older versions, you will probably not see the parameter recommendation list
  73. for functions after typing the open bracket. Some platforms (including OS X
  74. releases) do not ship a VIM with `+conceal`. You can check if your VIM has the
  75. feature with >
  76. :ver
  77. and look for "`+conceal`" (as opposed to "`-conceal`") or >
  78. :echo has('conceal')
  79. which will report 0 (not included) or 1 (included). If your VIM lacks this
  80. feature and you would like function parameter completion, you will need to
  81. build your own VIM, or use a package for your operating system that has this
  82. feature (such as MacVim on OS X, which also contains a console binary).
  83. ------------------------------------------------------------------------------
  84. 2.1. Installing manually *jedi-vim-installation-manually*
  85. 1a. Get the latest repository from Github: >
  86. git clone http://github.com/davidhalter/jedi-vim path/to/bundles/jedi-vim
  87. 1b. If you want to install jedi as a submodule instead, issue this command: >
  88. git clone --recursive http://github.com/davidhalter/jedi-vim
  89. 2. Put the plugin files into their respective folders in your vim runtime
  90. directory (usually ~/.vim). Be sure to pay attention to the directory
  91. structure!
  92. 3. Update the Vim help tags with >
  93. :helptags <path/to/vimruntime>/doc
  94. ------------------------------------------------------------------------------
  95. 2.1. Installing using Pathogen *jedi-vim-installation-pathogen*
  96. Pathogen simplifies installation considerably.
  97. 1.a Clone the git repository into your bundles directory: >
  98. git clone http://github.com/davidhalter/jedi-vim path/to/bundles/jedi-vim
  99. 1b. Again, if you want to install jedi as a submodule, use this command
  100. instead: >
  101. git clone --recursive http://github.com/davidhalter/jedi-vim
  102. ------------------------------------------------------------------------------
  103. 2.3. Installing using Vundle *jedi-vim-installation-vundle*
  104. 1. Vundle automatically downloads subrepositories as git submodules, so you
  105. will automatically get the jedi library with the jedi-vim plugin. Add the
  106. following to the Bundles section in your .vimrc file: >
  107. Plugin 'davidhalter/jedi-vim'
  108. 2. Issue the following command in Vim: >
  109. :PluginInstall
  110. Help tags are generated automatically, so you should be good to go.
  111. ------------------------------------------------------------------------------
  112. 2.4. Installing from Repositories *jedi-vim-installation-repos*
  113. Some Linux distributions have jedi-vim packages in their official
  114. repositories. On Arch Linux, install vim-jedi. On Debian (8+) or Ubuntu
  115. (14.04+) install vim-python-jedi.
  116. ==============================================================================
  117. 3. Supported Python features *jedi-vim-support*
  118. The Jedi library does all the hard work behind the scenes. It supports
  119. completion of a large number of Python features, among them:
  120. - Builtins
  121. - Multiple `return`s or `yield`s
  122. - Tuple assignments/array indexing/dictionary indexing
  123. - `with`-statement/exception handling
  124. - `*args` and `**kwargs`
  125. - Decorators, lambdas, closures
  126. - Generators, iterators
  127. - Some descriptors: `property`/`staticmethod`/`classmethod`
  128. - Some magic methods: `__call__`, `__iter__`, `__next__`, `__get__`,
  129. `__getitem__`, `__init__`
  130. - `list.append()`, `set.add()`, `list.extend()`, etc.
  131. - (Nested) list comprehensions and ternary expressions
  132. - Relative `import`s
  133. - `getattr()`/`__getattr__`/`__getattribute__`
  134. - Function annotations (py3k feature, are being ignored at the moment, but are
  135. parsed)
  136. - Class decorators (py3k feature, are being ignored at the moment, but are
  137. parsed)
  138. - Simple/usual `sys.path` modifications
  139. - `isinstance` checks for `if`/`while`/`assert` case, that doesn’t work with
  140. Jedi
  141. - And more...
  142. Note: This list is not necessarily up to date. For a complete list of
  143. features, please refer to the Jedi documentation at http://jedi.jedidjah.ch.
  144. ==============================================================================
  145. 4. Usage *jedi-vim-usage*
  146. With the default settings, autocompletion can be triggered by typing
  147. <Ctrl-Space>. The first entry will automatically be selected, so you can press
  148. <Return> to insert it into your code or keep typing and narrow down your
  149. completion options. The usual <C-X><C-O> and <C-P>/<C-N> keybindings work as
  150. well. Autocompletion is also triggered by typing a period in insert mode.
  151. Since periods rarely occur in Python code outside of method/import lookups,
  152. this is handy to have (but can be disabled).
  153. When it encounters a new module, jedi might take a few seconds to parse that
  154. module's contents. Afterwards, the contents are cached and completion will be
  155. almost instantaneous.
  156. ==============================================================================
  157. 5. Key Bindings *jedi-vim-keybindings*
  158. All keybindings can be mapped by setting the appropriate global option. For
  159. example, to set the keybinding for starting omnicompletion to <C-N> instead of
  160. <Ctrl-Space>, add the following setting to your .vimrc file: >
  161. let g:jedi#completions_command = "<C-N>"
  162. Note: If you have |g:jedi#auto_initialization| set to 0, you have to create
  163. a mapping yourself by calling a function: >
  164. " Using <C-N> for omnicompletion
  165. inoremap <silent> <buffer> <C-N> <c-x><c-o>
  166. " Use <localleader>r (by default <\-r>) for renaming
  167. nnoremap <silent> <buffer> <localleader>r :call jedi#rename()<cr>
  168. " etc.
  169. Note: You can set commands to '', which means that they are empty and not
  170. assigned. It's an easy way to "disable" functionality of jedi-vim.
  171. ------------------------------------------------------------------------------
  172. 5.1. `g:jedi#completions_command` *g:jedi#completions_command*
  173. Function: n/a; see above
  174. Default: <Ctrl-Space> Start completion
  175. Performs autocompletion (or omnicompletion, to be precise).
  176. Note: If you want to use <Tab> for completion, please install Supertab:
  177. https://github.com/ervandew/supertab.
  178. ------------------------------------------------------------------------------
  179. 5.2. `g:jedi#goto_assignments_command` *g:jedi#goto_assignments_command*
  180. Function: `jedi#goto_assignments()`
  181. Default: <leader>g Go to definition
  182. This function finds the first definition of the function/class under the
  183. cursor. It produces an error if the definition is not in a Python file.
  184. ------------------------------------------------------------------------------
  185. 5.3. `g:jedi#goto_definitions_command` *g:jedi#goto_definitions_command*
  186. Function: `jedi#goto_definitions()`
  187. Default: <leader>d Go to original definition
  188. This command tries to find the original definition of the function/class under
  189. the cursor. Just like the `jedi#goto_assignments()` function, it does not work
  190. if the definition isn't in a Python source file.
  191. The difference between `jedi#goto_assignments()` and `jedi#goto_definitions()`
  192. is that the latter performs recursive lookups. Take, for example, the
  193. following module structure: >
  194. # file1.py:
  195. from file2 import foo
  196. # file2.py:
  197. from file3 import bar as foo
  198. # file3.py
  199. def bar():
  200. pass
  201. The `jedi#goto_assignments()` function will take you to the >
  202. from file2 import foo
  203. statement in file1.py, while the `jedi#goto_definitions()` function will take
  204. you all the way to the >
  205. def bar():
  206. line in file3.py.
  207. ------------------------------------------------------------------------------
  208. 5.4. `g:jedi#documentation_command` *g:jedi#documentation_command*
  209. Function: `jedi#show_documentation()`
  210. Default: <K> Show pydoc documentation
  211. This shows the pydoc documentation for the item currently under the cursor.
  212. The documentation is opened in a horizontally split buffer.
  213. ------------------------------------------------------------------------------
  214. 5.5. `g:jedi#rename_command` *g:jedi#rename_command*
  215. Function: `jedi#rename()`
  216. Default: <leader>r Rename variables
  217. Jedi-vim deletes the word currently under the cursor and puts Vim in insert
  218. mode, where the user is expected to enter the new variable name. Upon leaving
  219. insert mode, jedi-vim then renames all occurences of the old variable name
  220. with the new one. The number of performed renames is displayed in the command
  221. line.
  222. ------------------------------------------------------------------------------
  223. 5.6. `g:jedi#usages_command` *g:jedi#usages_command*
  224. Function: `jedi#usages()`
  225. Default: <leader>n Show usages of a name.
  226. The quickfix window is populated with a list of all names which point to the
  227. definition of the name under the cursor.
  228. ------------------------------------------------------------------------------
  229. 5.7. Open module by name *:Pyimport*
  230. Function: `jedi#py_import(args)`
  231. Default: :Pyimport e.g. `:Pyimport os` shows os.py in VIM.
  232. Simulate an import and open that module in VIM.
  233. ==============================================================================
  234. 6. Configuration *jedi-vim-configuration*
  235. Note: You currently have to set these options in your .vimrc. Setting them in
  236. an ftplugin (e.g. ~/.vim/ftplugin/python/jedi-vim-settings.vim) will not work
  237. because jedi-vim is not set up as an filetype plugin, but as a "regular"
  238. plugin.
  239. ------------------------------------------------------------------------------
  240. 6.1. `g:jedi#auto_initialization` *g:jedi#auto_initialization*
  241. Upon initialization, jedi-vim performs the following steps:
  242. 1. Set the current buffers 'omnifunc' to its own completion function
  243. `jedi#completions`
  244. 2. Create mappings to commands specified in |jedi-vim-keybindings|
  245. 3. Call `jedi#configure_call_signatures()` if
  246. `g:jedi#show_call_signatures` is set
  247. You can disable the default initialization routine by setting this option to
  248. 0. Beware that you have to perform the above steps yourself, though.
  249. Options: 0 or 1
  250. Default: 1 (Perform automatic initialization)
  251. ------------------------------------------------------------------------------
  252. 6.2. `g:jedi#auto_vim_configuration` *g:jedi#auto_vim_configuration*
  253. Jedi-vim sets 'completeopt' to `menuone,longest,preview` by default, if
  254. 'completeopt' is not changed from Vim's default.
  255. It also remaps <Ctrl-C> to <Esc> in insert mode.
  256. If you want to keep your own configuration, disable this setting.
  257. Options: 0 or 1
  258. Default: 1 (Set 'completeopt' and mapping as described above)
  259. ------------------------------------------------------------------------------
  260. 6.3. `g:jedi#popup_on_dot` *g:jedi#popup_on_dot*
  261. Jedi-vim automatically starts completion upon typing a period in insert mode.
  262. However, when working with large modules, this can slow down your typing flow
  263. since you have to wait for jedi to parse the module and show the completion
  264. menu. By disabling this setting, completion is only started when you manually
  265. press the completion key.
  266. Options: 0 or 1
  267. Default: 1 (Start completion on typing a period)
  268. ------------------------------------------------------------------------------
  269. 6.4. `g:jedi#popup_select_first` *g:jedi#popup_select_first*
  270. Upon starting completion, jedi-vim can automatically select the first entry
  271. that pops up (without actually inserting it).
  272. This leads to a better typing flow: As you type more characters, the entries
  273. in the completion menu are narrowed down. If they are narrowed down enough,
  274. you can just press <Return> to insert the first match.
  275. Options: 0 or 1
  276. Default: 1 (Automatically select first completion entry)
  277. ------------------------------------------------------------------------------
  278. 6.5. `g:jedi#auto_close_doc` *g:jedi#auto_close_doc*
  279. When doing completion, jedi-vim shows the docstring of the currently selected
  280. item in a preview window. By default, this window is being closed after
  281. insertion of a completion item.
  282. Set this to 0 to leave the preview window open even after leaving insert mode.
  283. This could be useful if you want to browse longer docstrings.
  284. Options: 0 or 1
  285. Default: 1 (Automatically close preview window upon leaving insert mode)
  286. ------------------------------------------------------------------------------
  287. 6.6. `g:jedi#show_call_signatures` *g:jedi#show_call_signatures*
  288. Jedi-vim can display a small window detailing the arguments of the currently
  289. completed function and highlighting the currently selected argument. This can
  290. be disabled by setting this option to 0. Setting this option to 2 shows call
  291. signatures in the command line instead of a popup window.
  292. Options: 0, 1, or 2
  293. Default: 1 (Show call signatures window)
  294. Note: 'showmode' must be disabled for command line call signatures to be
  295. visible.
  296. Note: This setting is ignored if |g:jedi#auto_initialization| is set to 0. In
  297. that case, if you want to see call signatures, you have to set it up
  298. manually by calling a function in your configuration file: >
  299. call jedi#configure_call_signatures()
  300. ------------------------------------------------------------------------------
  301. 6.7. `g:jedi#use_tabs_not_buffers` *g:jedi#use_tabs_not_buffers*
  302. By default, jedi-vim opens a new tab if you use the "go to", "show
  303. definition", or "related names" commands. When you set this option to 0, they
  304. open in the current buffer instead.
  305. Options: 0 or 1
  306. Default: 1 (Command output is put in a new tab)
  307. ------------------------------------------------------------------------------
  308. 6.8. `g:jedi#squelch_py_warning` *g:jedi#squelch_py_warning*
  309. When Vim has not been compiled with +python, jedi-vim shows a warning to that
  310. effect and aborts loading itself. Set this to 1 to suppress that warning.
  311. Options: 0 or 1
  312. Default: 0 (Warning is shown)
  313. ------------------------------------------------------------------------------
  314. 6.9. `g:jedi#completions_enabled` *g:jedi#completions_enabled*
  315. If you don't want Jedi completion, but all the other features, you can disable
  316. it in favor of another completion engine (that probably also uses Jedi, like
  317. YCM).
  318. Options: 0 or 1
  319. Default: 1
  320. ------------------------------------------------------------------------------
  321. 6.10. `g:jedi#use_splits_not_buffers` *g:jedi#use_splits_not_buffers*
  322. If you want to open new split for "go to", you could set this option to the
  323. direction which you want to open a split with.
  324. Options: top, left, right, bottom or winwidth
  325. Default: "" (not enabled by default)
  326. Note: with the 'winwidth' option the window is split vertically or horizontally
  327. depending on the width of the window relative to 'textwidth'. This essentially
  328. means that if the window is big enough it will be split vertically but if it is
  329. small a horizontal split happens.
  330. ------------------------------------------------------------------------------
  331. 6.11. `g:jedi#force_py_version` *g:jedi#force_py_version*
  332. If you have installed both python 2 and python 3, you can force which one jedi
  333. should use by setting this variable. It forces the internal Vim command, which
  334. will be used for every jedi call to the respective python interpreter.
  335. The variable can be set in the .vimrc like this to force python 3:
  336. let g:jedi#force_py_version = 3
  337. This variable can be switched during runtime using the following function:
  338. Function: `jedi#force_py_version_switch()`
  339. or set directly using this function, which has the same name as the variable:
  340. Function: `jedi#force_py_version(py_version)`
  341. Options: 2 or 3
  342. Default: "auto" (will use sys.version_info from "python" in your $PATH)
  343. ==============================================================================
  344. 7. Testing *jedi-vim-testing*
  345. jedi-vim is being tested with a combination of vspec
  346. https://github.com/kana/vim-vspec and py.test http://pytest.org/.
  347. The tests are in the test subdirectory, you can run them calling::
  348. py.test
  349. The tests are automatically run with `travis
  350. <https://travis-ci.org/davidhalter/jedi-vim>`_.
  351. ==============================================================================
  352. 8. Contributing *jedi-vim-contributing*
  353. We love Pull Requests! Read the instructions in `CONTRIBUTING.md`.
  354. ==============================================================================
  355. 9. License *jedi-vim-license*
  356. Jedi-vim is licensed with the MIT license.
  357. vim: textwidth=78 tabstop=8 filetype=help:norightleft: