Python with vim

Preview:

DESCRIPTION

Slide of Python with vim, PyCon APAC 2014.

Citation preview

戴嘉駿 darkgerm <darkgerm@gmail.com>

Python in VIM

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

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

• 常用 Python 寫小工具自娛

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

2

Outline • The Python Interface to Vim

• The vim module

• Example - Conque

• Example - python-mode

3

4

The Python Interface to Vim

5

• Document: $VIMRUNTIME/doc/if_pyth.txt

• :help python

The Python Interface to Vim

6

• Check your Vim is compiled with +python.

• :version

The Python Interface to Vim

7

• :python {stmt}

• :python <<EOF

• ...multiline...

• EOF

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 %

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

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

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

The vim module • Vim Tabpage Object

• t.number

• t.windows

• window list

• t.window

• current window

• t.vars

• t: variables

12

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

The vim module • Vim Buffer Object

• b[linenr] = line

• The content of the buffer.

• b.name

• b.vars

• b: variables

• b.options

14

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

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

15

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

Thank you for listening

17

• Q & A

Recommended