设为首页 收藏本站
查看: 470|回复: 0

[经验分享] ZT---VIM as Python IDE

[复制链接]

尚未签到

发表于 2017-4-27 07:03:52 | 显示全部楼层 |阅读模式
  Original Article please go to http://blog.dispatched.ch/2009/05/24/vim-as-python-ide/
  Finding the perfect IDE for Python isn’t an easy feat. There are a great many to chose from, but even though some of them offer really nifty features, I can’t help myself but feel attracted to VIM anyway. I feel that no IDE accomplishes the task of giving the comfort of completepower over the code - something is always missing out. This is why I always come back to using IDLE and VIM. Those two seem to be best companions when doing some quick and agile hacking - but when it comes to managing bigger and longer term projects, this combo needs some tweaking. But when it’s done, VIM will be a powerful IDE for Python - including code completion(with pydoc display), graphical debugging, task-management and a project view.
  This is where we are going:
DSC0000.png

  So, these are my thoughts on a VIM setup for coding (Python).
  Modern GUI VIM implementations like GVIM or MacVIM give the user the opportunity to organize their open files in tabs. This might look convenient, but to me it is rather bad practice, because a second tab will not be in the in the same buffer scope as the first one which takesaway from future interaction options between the two. Using MiniBufExplorer, however, gives the user tabs(not only in the GUI, but also in command line) and leaves the classic bufferinteraction intact.
DSC0001.png

  Being able to neatly work on multiple files, the user still misses the potential his favourite IDE gives him in visualizing classes, functions and variables. Luckily there are quite a few plugins around toaccomplish this task just as well. My favourite one would be TagList. TagList uses Exuberant Ctagsfor actually generating the tags(note: it really relies on this specific version of ctags - preinstalled implementations on UNIX systemswon’t work).
DSC0002.png

  A lot of coders have the habit of using TODO or FIXME statements in their code. Other IDEs often rely on having good third party project management software, but not VIM. There are great plugins like Tasklistreminding the programmer of those lines of code. Tasklist even implements custom lists - to me that’s an incredibleproductivity gain.
DSC0003.png

  In these times, the programmer knows his or her programming language more or less by interactively finding out what it can do. Therefore codecompletion(sometimes also called IntelliSense*ugh*) is a major feature.I have heard  many people saying that this is where VIM fails - but luckily they are plain wrong(; In V7, VIM introduced omni completion- given it is configured to recognize Python (if not, this feature is only a pluginaway) Ctrl+x Ctrl+o opens a drop down dialog like any other IDE - even the whole Pydoc gets to be displayed in a split window.
DSC0004.png

  Probably the most wanted feature(besides code completion) is debugging graphically. VimPDBis a plugin that lets you do just that(. I acknowledge it is no complete substitution for a full fledged graphical debugger, but I honour the thought that having to rely on a debugger (often), is a hint of bad design.
DSC0005.png

  –
 

From the eye-candy to the implementation. Don’t worry, it’s no sorcery.

First of all, make sure you have VIM version 7.x installed, compiled with Python support. To check for the second, enter :python print “hello, world”into VIM. If you seean error message like “E319: Sorry, the command is not available inthis version”, then it’s time to get a new one. If you’re on a Mac, just install MacVIM(there’s also a binary for the console in /Applications/MacVim.app/Contents/MacOS/). If you’re on Windows, GVIM will suffice(for versions != 2.4 search for the right plugin). If you’re on any other machine, you will probably know how to compile your very own VIM with Python support.

Second, check if you have a plugin directory. In Unix it would typically be located in $HOME/.vim/plugin,in Windows in the Program Files directory. If it doesn’t exist, create it.

Now, let’s start with the MiniBufExplorer. Getit and copy it into your plugin directory. To start it automatically when needed and be able to use it with keyboard and mouse commands, append these lines in your vimrc configuration:

  let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
For a project view, get TagListand Exuberant Ctags. To install Ctags, unpack it, go into the directory and do a compile/install via:

  ./configure && sudo make install
  Ctags will then be installed in /usr/local/bin. When using a Windows machine, I recommend Cygwinwith GCC and Make; it’ll work just fine. If you don’t want to tamper with your original ctags installation, you can propagate the location to VIM by appending the following line to vimrc:
  let Tlist_Ctags_Cmd='/usr/local/bin/ctags'
  To install TagList, just drop it into VIMs plugin directory. You willnow be able to use the project view by typing the command :TlistToggle.
  Tasklistis a simple plugin, too. Copying it into the plugin directory will suffice. I like to have shortcuts and have added

map T :TaskList<CR>
map P :TlistToggle<CR>

  to vimrc. Pressing T will then open the TaskList if there are any tasks to process. q quits the TaskList again.
  VimPDBis a plugin, as well. Install as before and see the readme for documentation. If it doesn’t work out of the box, watch for the known issues.
  To enable code(omni) completion, add this line to your vimrc:
  autocmd FileType python set omnifunc=pythoncomplete#Complete
  If it doesn’t work then, you’ll need this plugin.
My last two recommondations are setting these lines to comply to PEP 8(Pythons’style guide) and to have decent eye candy:

  set expandtab
set textwidth=79
set tabstop=8
set softtabstop=4
set shiftwidth=4
set autoindent
:syntax on
  There are certainly a lot more flags to help productivity, but those will probably be more user specific.
  Have fun coding Python while not being bound to a specific IDE, but having all the benefits of VIM bundled with a few helping hands. Enjoy, everyone.
  If you liked this article, please feel free to re-tweet it and let others know.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-369658-1-1.html 上篇帖子: Python 操作 EXCEL 2(ZT) 下篇帖子: 用Python做图像处理
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表