SlideShare uma empresa Scribd logo
1 de 17
Baixar para ler offline
戴嘉駿 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

Mais conteúdo relacionado

Semelhante a Python with vim

Pharo Arm Status
Pharo Arm StatusPharo Arm Status
Pharo Arm StatusESUG
 
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/19Akihiro Okuno
 
Python on a chip
Python on a chipPython on a chip
Python on a chipstoggi
 
Introduction to Python.pdf
Introduction to Python.pdfIntroduction to Python.pdf
Introduction to Python.pdfRahul Mogal
 
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 PythonDavid Beazley (Dabeaz LLC)
 
Barcamp Bangkhen :: Robot Framework
Barcamp Bangkhen :: Robot FrameworkBarcamp Bangkhen :: Robot Framework
Barcamp Bangkhen :: Robot FrameworkSomkiat Puisungnoen
 
Writing a Python C extension
Writing a Python C extensionWriting a Python C extension
Writing a Python C extensionSqreen
 
Python on FreeBSD
Python on FreeBSDPython on FreeBSD
Python on FreeBSDpycontw
 
Sublime Text3 for Django Development
Sublime Text3 for Django DevelopmentSublime Text3 for Django Development
Sublime Text3 for Django DevelopmentWilly Liu
 
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.pptxNaglaaAbdelhady
 
Torando demo
Torando demoTorando demo
Torando demoCRidenour
 
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...Felipe Prado
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programmingChetan Giridhar
 

Semelhante a 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
 

Último

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 

Último (20)

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 

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