README.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. Python-mode, Python in VIM
  2. ##########################
  3. Python-mode is a vim plugin that allows you to use the pylint_, rope_, pydoc_, pyflakes_, pep8_, mccabe_ libraries in vim to provide
  4. features like python code looking for bugs, refactoring and some other useful things.
  5. This plugin allow you create python code in vim very easily.
  6. There is no need to install the pylint_, rope_ or any used python library on your system.
  7. - Python objects and motion (]], 3[[, ]]M, vaC, viM, daC, ciM, ...)
  8. - Folding of python code
  9. - Virtualenv support
  10. - Highlight syntax errors
  11. - Highlight and auto fix unused imports
  12. - Many linters (pylint_, pyflakes_, ...) that can be run simultaneously
  13. - Strong code completion
  14. - Code refactoring
  15. - Python documentation
  16. - Run python code
  17. - Go to definition
  18. - Powerful customization
  19. - And more, more ...
  20. See (very old) screencast here: http://t.co/3b0bzeXA (sorry for quality, this is my first screencast)
  21. .. contents::
  22. Changelog
  23. =========
  24. ## 2012-08-02 0.6.5
  25. -------------------
  26. * Updated Pep8 to version 1.3.3
  27. * Updated Pylint to version 0.25.2
  28. * Fixed virtualenv support for windows users
  29. * Added pymode modeline ':help PythonModeModeline'
  30. * Added diagnostic tool ':call pymode#troubleshooting#Test()'
  31. * Added `PyLintAuto` command ':help PyLintAuto'
  32. * Code checking is async operation now
  33. * More, more fast the pymode folding
  34. * Repaired execution of python code
  35. Requirements
  36. ============
  37. - VIM >= 7.0 with python support
  38. (also ``--with-features=big`` if you want use g:pymode_lint_signs)
  39. How to install
  40. ==============
  41. Using pathogen_ (recomended)
  42. ----------------------------
  43. ::
  44. % cd ~/.vim
  45. % mkdir -p bundle && cd bundle
  46. % git clone git://github.com/klen/python-mode.git
  47. - Enable pathogen_ in your ``~/.vimrc``: ::
  48. " Pathogen load
  49. filetype off
  50. call pathogen#infect()
  51. call pathogen#helptags()
  52. filetype plugin indent on
  53. syntax on
  54. Manually
  55. --------
  56. ::
  57. % git clone git://github.com/klen/python-mode.git
  58. % cd python-mode
  59. % cp -R * ~/.vim
  60. Then rebuild **helptags** in vim::
  61. :helptags ~/.vim/doc/
  62. .. note:: **filetype-plugin** (``:help filetype-plugin-on``) and **filetype-indent** (``:help filetype-indent-on``)
  63. must be enabled for use python-mode.
  64. Troubleshooting
  65. ===============
  66. If your python-mode dont work, type command: ::
  67. :call pymode#troubleshooting#Test()
  68. And fix warnings or copy output and send it to me (ex. with github issue).
  69. Settings
  70. ========
  71. .. note:: Also you can see vim help. ``:help PythonModeOptions``
  72. To change this settings, edit your ``~/.vimrc``: ::
  73. " Disable pylint checking every save
  74. let g:pymode_lint_write = 0
  75. " Set key 'R' for run python code
  76. let g:pymode_run_key = 'R'
  77. Show documentation
  78. ------------------
  79. Default values: ::
  80. " Load show documentation plugin
  81. let g:pymode_doc = 1
  82. " Key for show python documentation
  83. let g:pymode_doc_key = 'K'
  84. Run python code
  85. ---------------
  86. Default values: ::
  87. " Load run code plugin
  88. let g:pymode_run = 1
  89. " Key for run python code
  90. let g:pymode_run_key = '<leader>r'
  91. Code checking
  92. -------------
  93. Default values: ::
  94. " Load pylint code plugin
  95. let g:pymode_lint = 1
  96. " Switch pylint, pyflakes, pep8, mccabe code-checkers
  97. " Can have multiply values "pep8,pyflakes,mcccabe"
  98. let g:pymode_lint_checker = "pyflakes,pep8,mccabe"
  99. " Skip errors and warnings
  100. " E.g. "E501,W002", "E2,W" (Skip all Warnings and Errors startswith E2) and etc
  101. let g:pymode_lint_ignore = "E501"
  102. " Select errors and warnings
  103. " E.g. "E4,W"
  104. let g:pymode_lint_select = ""
  105. " Run linter on the fly
  106. let g:pymode_lint_onfly = 0
  107. " Pylint configuration file
  108. " If file not found use 'pylintrc' from python-mode plugin directory
  109. let g:pymode_lint_config = "$HOME/.pylintrc"
  110. " Check code every save
  111. let g:pymode_lint_write = 1
  112. " Auto open cwindow if errors be finded
  113. let g:pymode_lint_cwindow = 1
  114. " Show error message if cursor placed at the error line
  115. let g:pymode_lint_message = 1
  116. " Auto jump on first error
  117. let g:pymode_lint_jump = 0
  118. " Hold cursor in current window
  119. " when quickfix is open
  120. let g:pymode_lint_hold = 0
  121. " Place error signs
  122. let g:pymode_lint_signs = 1
  123. " Maximum allowed mccabe complexity
  124. let g:pymode_lint_mccabe_complexity = 8
  125. " Minimal height of pylint error window
  126. let g:pymode_lint_minheight = 3
  127. " Maximal height of pylint error window
  128. let g:pymode_lint_maxheight = 6
  129. .. note::
  130. Pylint options (ex. disable messages) may be defined in ``$HOME/pylint.rc``
  131. See pylint documentation: http://pylint-messages.wikidot.com/all-codes
  132. Rope refactoring library
  133. ------------------------
  134. Default values: ::
  135. " Load rope plugin
  136. let g:pymode_rope = 1
  137. " Auto create and open ropeproject
  138. let g:pymode_rope_auto_project = 1
  139. " Enable autoimport
  140. let g:pymode_rope_enable_autoimport = 1
  141. " Auto generate global cache
  142. let g:pymode_rope_autoimport_generate = 1
  143. let g:pymode_rope_autoimport_underlineds = 0
  144. let g:pymode_rope_codeassist_maxfixes = 10
  145. let g:pymode_rope_sorted_completions = 1
  146. let g:pymode_rope_extended_complete = 1
  147. let g:pymode_rope_autoimport_modules = ["os","shutil","datetime"]
  148. let g:pymode_rope_confirm_saving = 1
  149. let g:pymode_rope_global_prefix = "<C-x>p"
  150. let g:pymode_rope_local_prefix = "<C-c>r"
  151. let g:pymode_rope_vim_completion = 1
  152. let g:pymode_rope_guess_project = 1
  153. let g:pymode_rope_goto_def_newwin = ""
  154. let g:pymode_rope_always_show_complete_menu = 0
  155. Automatically folding of python code
  156. --------------------------------------
  157. Default values: ::
  158. " Enable python folding
  159. let g:pymode_folding = 0
  160. Vim python motions and operators
  161. --------------------------------
  162. Default values: ::
  163. " Enable python objects and motion
  164. let g:pymode_motion = 1
  165. Virtualenv support
  166. ------------------
  167. Default values: ::
  168. " Auto fix vim python paths if virtualenv enabled
  169. let g:pymode_virtualenv = 1
  170. Other stuff
  171. -----------
  172. Default values: ::
  173. " Additional python paths
  174. let g:pymode_paths = []
  175. " Load breakpoints plugin
  176. let g:pymode_breakpoint = 1
  177. " Key for set/unset breakpoint
  178. let g:pymode_breakpoint_key = '<leader>b'
  179. " Autoremove unused whitespaces
  180. let g:pymode_utils_whitespaces = 1
  181. " Enable pymode indentation
  182. let g:pymode_indent = 1
  183. " Set default pymode python options
  184. let g:pymode_options = 1
  185. Syntax highlight
  186. ----------------
  187. Default values: ::
  188. " Enable pymode's custom syntax highlighting
  189. let g:pymode_syntax = 1
  190. " Enable all python highlightings
  191. let g:pymode_syntax_all = 1
  192. " Highlight "print" as function
  193. let g:pymode_syntax_print_as_function = 0
  194. " Highlight indentation errors
  195. let g:pymode_syntax_indent_errors = g:pymode_syntax_all
  196. " Highlight trailing spaces
  197. let g:pymode_syntax_space_errors = g:pymode_syntax_all
  198. " Highlight string formatting
  199. let g:pymode_syntax_string_formatting = g:pymode_syntax_all
  200. " Highlight str.format syntax
  201. let g:pymode_syntax_string_format = g:pymode_syntax_all
  202. " Highlight string.Template syntax
  203. let g:pymode_syntax_string_templates = g:pymode_syntax_all
  204. " Highlight doc-tests
  205. let g:pymode_syntax_doctests = g:pymode_syntax_all
  206. " Highlight builtin objects (__doc__, self, etc)
  207. let g:pymode_syntax_builtin_objs = g:pymode_syntax_all
  208. " Highlight builtin functions
  209. let g:pymode_syntax_builtin_funcs = g:pymode_syntax_all
  210. " Highlight exceptions
  211. let g:pymode_syntax_highlight_exceptions = g:pymode_syntax_all
  212. " For fast machines
  213. let g:pymode_syntax_slow_sync = 0
  214. Default keys
  215. ============
  216. .. note:: Also you can see vim help ``:help PythonModeKeys``
  217. ============== =============
  218. Keys Command
  219. ============== =============
  220. **K** Show python docs (g:pymode_doc enabled)
  221. -------------- -------------
  222. **<C-Space>** Rope autocomplete (g:pymode_rope enabled)
  223. -------------- -------------
  224. **<C-c>g** Rope goto definition (g:pymode_rope enabled)
  225. -------------- -------------
  226. **<C-c>d** Rope show documentation (g:pymode_rope enabled)
  227. -------------- -------------
  228. **<C-c>f** Rope find occurrences (g:pymode_rope enabled)
  229. -------------- -------------
  230. **<Leader>r** Run python (g:pymode_run enabled)
  231. -------------- -------------
  232. **<Leader>b** Set, unset breakpoint (g:pymode_breakpoint enabled)
  233. -------------- -------------
  234. [[ Jump on previous class or function (normal, visual, operator modes)
  235. -------------- -------------
  236. ]] Jump on next class or function (normal, visual, operator modes)
  237. -------------- -------------
  238. [M Jump on previous class or method (normal, visual, operator modes)
  239. -------------- -------------
  240. ]M Jump on next class or method (normal, visual, operator modes)
  241. -------------- -------------
  242. aC C Select a class. Ex: vaC, daC, dC, yaC, yC, caC, cC (normal, operator modes)
  243. -------------- -------------
  244. iC Select inner class. Ex: viC, diC, yiC, ciC (normal, operator modes)
  245. -------------- -------------
  246. aM M Select a function or method. Ex: vaM, daM, dM, yaM, yM, caM, cM (normal, operator modes)
  247. -------------- -------------
  248. iM Select inner function or method. Ex: viM, diM, yiM, ciM (normal, operator modes)
  249. ============== =============
  250. .. note:: See also ``:help ropevim.txt``
  251. Commands
  252. ========
  253. .. note:: Also you can see vim help ``:help PythonModeCommands``
  254. ==================== =============
  255. Command Description
  256. ==================== =============
  257. :Pydoc <args> Show python documentation
  258. -------------------- -------------
  259. PyLintToggle Enable, disable pylint
  260. -------------------- -------------
  261. PyLintCheckerToggle Toggle code checker (pylint, pyflakes)
  262. -------------------- -------------
  263. PyLint Check current buffer
  264. -------------------- -------------
  265. PyLintAuto Automatic fix PEP8 errors
  266. -------------------- -------------
  267. Pyrun Run current buffer in python
  268. ==================== =============
  269. .. note:: See also ``:help ropevim.txt``
  270. F.A.Q.
  271. ======
  272. Rope completion is very slow
  273. ----------------------------
  274. To work rope_ creates a service directory: ``.ropeproject``.
  275. If ``g:pymode_rope_guess_project`` set (by default) and ``.ropeproject`` in current dir not found, rope scan ``.ropeproject`` on every dir in parent path.
  276. If rope finded ``.ropeproject`` in parent dirs, rope set project for all child dir and scan may be slow for many dirs and files.
  277. Solutions:
  278. - Disable ``g:pymode_rope_guess_project`` to make rope always create ``.ropeproject`` in current dir.
  279. - Delete ``.ropeproject`` from dip parent dir to make rope create ``.ropeproject`` in current dir.
  280. - Press ``<C-x>po`` or ``:RopeOpenProject`` to make force rope create ``.ropeproject`` in current dir.
  281. Pylint check is very slow
  282. -------------------------
  283. In some projects pylint_ may check slowly, because it also scan imported modules if posible.
  284. Try use pyflakes_, see ``:h 'pymode_lint_checker'``.
  285. .. note:: You may ``set exrc`` and ``set secure`` in your ``vimrc`` for auto set custom settings from ``.vimrc`` from your projects directories.
  286. Example: On Flask projects I automaticly set ``g:pymode_lint_checker = "pyflakes"``, on django ``g:pymode_lint_cheker = "pylint"``
  287. OSX cannot import urandom
  288. -------------------------
  289. See: https://groups.google.com/forum/?fromgroups=#!topic/vim_dev/2NXKF6kDONo
  290. The sequence of commands that fixed this: ::
  291. brew unlink python
  292. brew unlink macvim
  293. brew remove macvim
  294. brew install -v --force macvim
  295. brew link macvim
  296. brew link python
  297. Bugtracker
  298. ===========
  299. If you have any suggestions, bug reports or
  300. annoyances please report them to the issue tracker
  301. at https://github.com/klen/python-mode/issues
  302. Contributing
  303. ============
  304. Development of pylint-mode happens at github: https://github.com/klen/python-mode
  305. Copyright
  306. =========
  307. Copyright (C) 2012 Kirill Klenov (klen_)
  308. **Rope**
  309. Copyright (C) 2006-2010 Ali Gholami Rudi
  310. Copyright (C) 2009-2010 Anton Gritsay
  311. **Pylint**
  312. Copyright (C) 2003-2011 LOGILAB S.A. (Paris, FRANCE).
  313. http://www.logilab.fr/
  314. **Pyflakes**:
  315. Copyright (c) 2005 Divmod, Inc.
  316. http://www.divmod.com/
  317. **PEP8**
  318. Copyright (C) 2006 Johann C. Rocholl <johann@rocholl.net>
  319. http://github.com/jcrocholl/pep8
  320. **autopep8**:
  321. Copyright (c) 2012 hhatto <hhatto.jp@gmail.com>
  322. https://github.com/hhatto/autopep8
  323. **Python syntax for vim**
  324. Copyright (c) 2010 Dmitry Vasiliev
  325. http://www.hlabs.spb.ru/vim/python.vim
  326. **PEP8 VIM indentation**
  327. Copyright (c) 2012 Hynek Schlawack <hs@ox.cx>
  328. http://github.com/hynek/vim-python-pep8-indent
  329. License
  330. =======
  331. Licensed under a `GNU lesser general public license`_.
  332. If you like this plugin, you can send me postcard :)
  333. My address is here: "Russia, 143401, Krasnogorsk, Shkolnaya 1-19" to "Kirill Klenov".
  334. **Thanks for support!**
  335. .. _GNU lesser general public license: http://www.gnu.org/copyleft/lesser.html
  336. .. _klen: http://klen.github.com/
  337. .. _pylint: http://www.logilab.org/857
  338. .. _pyflakes: http://pypi.python.org/pypi/pyflakes
  339. .. _rope: http://rope.sourceforge.net/
  340. .. _pydoc: http://docs.python.org/library/pydoc.html
  341. .. _pathogen: https://github.com/tpope/vim-pathogen
  342. .. _pep8: http://pypi.python.org/pypi/pep8
  343. .. _mccabe: http://en.wikipedia.org/wiki/Cyclomatic_complexity