python und Vim

   


pyCologne 11.11.2015

Christian Geier

Vim ist keine IDE!

und willl auch keine sein

UNIX ist (m)eine IDE!

IDEs enthalten (meist)

  • compiler/interpreter
  • build automation tools
  • debugger
  • version control system
  • project management tools
  • refactoring tools
  • source code editor

UNIX als (python) IDE

  • interpreter: cpython (ipython), pypy, ...
  • debugger: pdb, pdb++, ipdb, pudb, bugjar, canopy, ...
  • vcs: git, svn, mercurial, ...
  • project management tools: ls, mv, rm, cp, grep, ack, ...
  • refactoring tools: rope, jedi, ...
  • source code editor: Vim, emacs, sublime text, gedit, ...

Vorteile

  • sehr modular
  • ist auch $PROGRAMMING_LANG IDE, $\LaTeX$ Umgebung, Mail Umgebung, ...
  • alle Tools nur einmal lernen

Nachteile

  • sehr modular
  • teilweise fehlende Entdeckbarkeit

Vim als Texteditor-Komponente für python

  • sehr konfigurierbar (default Werte oft historisch bedingt)
  • stark durch plugins erweiterbar (von denen es tausende gibt)

Konfiguration

python specific vim Konfiguration:

in ~/.vimrc oder ~/.vim/ftplugin/python.vim

setlocal tabstop=4
setlocal shiftwidth=4
setlocal expandtab
setlocal cindent
setlocal smarttab
setlocal formatoptions=croql
setlocal number

setlocal textwidth=80
setlocal colorcolumn=80
highlight OverLength ctermbg=darkred ctermfg=white guibg=#592929
match OverLength /\%106v.*/

One Stop turn-vim-into-a-python-IDE solution: python-mode (ich bin kein Fan)

Plugins (Beispiele) DEMO-Time

neomake config

let g:neomake_python_enabled_makers = ['flake8', 'pep8']
" E501 is line length of 80 characters, I don't want to see all those errors
let g:neomake_python_flake8_maker = { 'args': ['--ignore=E501'], }
let g:neomake_python_pep8_maker = { 'args': ['--max-line-length=105'], }

jedia config

let g:jedi#auto_vim_configuration = 0
let g:jedi#popup_on_dot = 0
let g:jedi#popup_select_first = 0
let g:jedi#completions_enabled = 0
let g:jedi#completions_command = ""
let g:jedi#show_call_signatures = "1"

let g:jedi#goto_assignments_command = "<leader>pa"
let g:jedi#goto_definitions_command = "<leader>pd"
let g:jedi#documentation_command = "<leader>pk"
let g:jedi#usages_command = "<leader>pu"
let g:jedi#rename_command = "<leader>pr"

neovim

  • refactored vim, with better defaults, embedding, and a lot of other cool features
  • v0.1 gerade released, aber schon relativ stabil (derzeit kein Windows suport)

lade python integration pip install neovim, linke Vim config: ln -s ~/.vim ~/.config/nvim; ln -s ~/.vimrc ~/.config/nvim/init.vim

killer feature

asynchronous job-control

z.B. linting mit neomake im Hintergrund, auch bei großeen Files kein Warten