17
戴嘉駿 darkgerm <[email protected]> Python in VIM

Python with vim

  • Upload
    -

  • View
    520

  • Download
    3

Embed Size (px)

DESCRIPTION

Slide of Python with vim, PyCon APAC 2014.

Citation preview

Page 1: Python with vim

戴嘉駿 darkgerm <[email protected]>

Python in VIM

Page 2: Python with vim

About darkgerm • 目前就讀於交通大學資工系大四

• 熱愛 Python 及資訊技術的大學生

• 常用 Python 寫小工具自娛

• Vim 重度使用者,即使在 Windows 上也要使用 Vim

2

Page 3: Python with vim

Outline • The Python Interface to Vim

• The vim module

• Example - Conque

• Example - python-mode

3

Page 4: Python with vim

4

Page 5: Python with vim

The Python Interface to Vim

5

• Document: $VIMRUNTIME/doc/if_pyth.txt

• :help python

Page 6: Python with vim

The Python Interface to Vim

6

• Check your Vim is compiled with +python.

• :version

Page 7: Python with vim

The Python Interface to Vim

7

• :python {stmt}

• :python <<EOF

• ...multiline...

• EOF

Page 8: Python with vim

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 %

Page 9: Python with vim

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

Page 10: Python with vim

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

Page 11: Python with vim

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

Page 12: Python with vim

The vim module • Vim Tabpage Object

• t.number

• t.windows

• window list

• t.window

• current window

• t.vars

• t: variables

12

Page 13: Python with vim

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

Page 14: Python with vim

The vim module • Vim Buffer Object

• b[linenr] = line

• The content of the buffer.

• b.name

• b.vars

• b: variables

• b.options

14

Page 15: Python with vim

Example - Conque • https://code.google.com/p/conque/

• A terminal emulator which uses a Vim buffer to display the program output.

15

Page 16: Python with vim

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

Page 17: Python with vim

Thank you for listening

17

• Q & A