Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Python with vim

2,023 views

Published on

Slide of Python with vim, PyCon APAC 2014.

Published in: Software, Technology
  • Be the first to comment

Python with vim

  1. 1. 戴嘉駿 darkgerm <darkgerm@gmail.com> Python in VIM
  2. 2. About darkgerm • 目前就讀於交通大學資工系大四 • 熱愛 Python 及資訊技術的大學生 • 常用 Python 寫小工具自娛 • Vim 重度使用者,即使在 Windows 上也要使用 Vim 2
  3. 3. Outline • The Python Interface to Vim • The vim module • Example - Conque • Example - python-mode 3
  4. 4. 4
  5. 5. The Python Interface to Vim 5 • Document: $VIMRUNTIME/doc/if_pyth.txt • :help python
  6. 6. The Python Interface to Vim 6 • Check your Vim is compiled with +python. • :version
  7. 7. The Python Interface to Vim 7 • :python {stmt} • :python <<EOF • ...multiline... • EOF
  8. 8. The Python Interface to Vim 8 • :pydo {body} • Execute "def _vim_pydo(line, linenr)" • :pyfile {file} • Find the sum of line • :pydo return str(sum(map(int, line.split()))) • Execute the current file • :pyfile %
  9. 9. The vim module • 'import vim' in vim • :python import vim • Via vim module, Python code can access: • vim windows • vim buffers • read and change vim buffers • ...... 9
  10. 10. The vim module • vim.command(str) • Execute the vim (ex-mode) command. • vim.eval(str) • Evaluates the vim expression. • vim.chdir(*args, **kwargs) • Change the current directory. 10
  11. 11. The vim module • vim.tabpages • A tabpage may contain many windows. • vim.windows • vim.buffers • vim.current • vim.current.tabpage • vim.curent.window • vim.current.buffer 11
  12. 12. The vim module • Vim Tabpage Object • t.number • t.windows • window list • t.window • current window • t.vars • t: variables 12
  13. 13. The vim module • Vim Window Object • w.number • w.buffer • w.cursor • w.height, w.width • w.vars • w: variables • w.tabpage • Point to its tabpage. 13
  14. 14. The vim module • Vim Buffer Object • b[linenr] = line • The content of the buffer. • b.name • b.vars • b: variables • b.options 14
  15. 15. Example - Conque • https://code.google.com/p/conque/ • A terminal emulator which uses a Vim buffer to display the program output. 15
  16. 16. Example - python-mode • https://github.com/klen/python-mode • A vim plugin that helps you to create python code very quickly by utilizing libraries including pylint, rope, pydoc, pyflakes, pep8, and mccabe for features like static analysis, refactoring, folding, completion, documentation, and more. 16
  17. 17. Thank you for listening 17 • Q & A

×