SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
戴嘉駿 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

Contenu connexe

Similaire à Python with vim

Start Vim script @Ujihisa.vim 2011/11/19
Start Vim script @Ujihisa.vim 2011/11/19Start Vim script @Ujihisa.vim 2011/11/19
Start Vim script @Ujihisa.vim 2011/11/19
Akihiro Okuno
 
Introduction to Python.pdf
Introduction to Python.pdfIntroduction to Python.pdf
Introduction to Python.pdf
Rahul Mogal
 
Torando demo
Torando demoTorando demo
Torando demo
CRidenour
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
Chetan Giridhar
 

Similaire à Python with vim (20)

Pharo Arm Status
Pharo Arm StatusPharo Arm Status
Pharo Arm Status
 
DSA Day 2 PPT.pdf
DSA Day 2 PPT.pdfDSA Day 2 PPT.pdf
DSA Day 2 PPT.pdf
 
Start Vim script @Ujihisa.vim 2011/11/19
Start Vim script @Ujihisa.vim 2011/11/19Start Vim script @Ujihisa.vim 2011/11/19
Start Vim script @Ujihisa.vim 2011/11/19
 
Python on a chip
Python on a chipPython on a chip
Python on a chip
 
Introduction to Python.pdf
Introduction to Python.pdfIntroduction to Python.pdf
Introduction to Python.pdf
 
Introduction to Robot Framework
Introduction to Robot FrameworkIntroduction to Robot Framework
Introduction to Robot Framework
 
zhng your vim
zhng your vimzhng your vim
zhng your vim
 
Using SWIG to Control, Prototype, and Debug C Programs with Python
Using SWIG to Control, Prototype, and Debug C Programs with PythonUsing SWIG to Control, Prototype, and Debug C Programs with Python
Using SWIG to Control, Prototype, and Debug C Programs with Python
 
Barcamp Bangkhen :: Robot Framework
Barcamp Bangkhen :: Robot FrameworkBarcamp Bangkhen :: Robot Framework
Barcamp Bangkhen :: Robot Framework
 
Python Programming Essentials - M4 - Editors and IDEs
Python Programming Essentials - M4 - Editors and IDEsPython Programming Essentials - M4 - Editors and IDEs
Python Programming Essentials - M4 - Editors and IDEs
 
Writing a Python C extension
Writing a Python C extensionWriting a Python C extension
Writing a Python C extension
 
Python on FreeBSD
Python on FreeBSDPython on FreeBSD
Python on FreeBSD
 
Sublime Text3 for Django Development
Sublime Text3 for Django DevelopmentSublime Text3 for Django Development
Sublime Text3 for Django Development
 
IS - section 1 - modifiedFinal information system.pptx
IS - section 1 - modifiedFinal information system.pptxIS - section 1 - modifiedFinal information system.pptx
IS - section 1 - modifiedFinal information system.pptx
 
Python programming 2nd
Python programming 2ndPython programming 2nd
Python programming 2nd
 
Torando demo
Torando demoTorando demo
Torando demo
 
DEF CON 23 - Yuwei Zheng and Haoqi Shan - build a free cellular traffic captu...
DEF CON 23 - Yuwei Zheng and Haoqi Shan - build a free cellular traffic captu...DEF CON 23 - Yuwei Zheng and Haoqi Shan - build a free cellular traffic captu...
DEF CON 23 - Yuwei Zheng and Haoqi Shan - build a free cellular traffic captu...
 
Python Tutorial for Beginner
Python Tutorial for BeginnerPython Tutorial for Beginner
Python Tutorial for Beginner
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
 
Introduction to robot framework
Introduction to robot frameworkIntroduction to robot framework
Introduction to robot framework
 

Dernier

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Dernier (20)

%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 

Python with vim

  • 2. About darkgerm • 目前就讀於交通大學資工系大四 • 熱愛 Python 及資訊技術的大學生 • 常用 Python 寫小工具自娛 • Vim 重度使用者,即使在 Windows 上也要使用 Vim 2
  • 3. Outline • The Python Interface to Vim • The vim module • Example - Conque • Example - python-mode 3
  • 4. 4
  • 5. The Python Interface to Vim 5 • Document: $VIMRUNTIME/doc/if_pyth.txt • :help python
  • 6. The Python Interface to Vim 6 • Check your Vim is compiled with +python. • :version
  • 7. The Python Interface to Vim 7 • :python {stmt} • :python <<EOF • ...multiline... • EOF
  • 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. 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. 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. 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. The vim module • Vim Tabpage Object • t.number • t.windows • window list • t.window • current window • t.vars • t: variables 12
  • 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. The vim module • Vim Buffer Object • b[linenr] = line • The content of the buffer. • b.name • b.vars • b: variables • b.options 14
  • 15. Example - Conque • https://code.google.com/p/conque/ • A terminal emulator which uses a Vim buffer to display the program output. 15
  • 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. Thank you for listening 17 • Q & A