`
flyaswish
  • 浏览: 10795 次
  • 性别: Icon_minigender_1
  • 来自: 无锡
最近访客 更多访客>>
社区版块
存档分类
最新评论

ZT---VIM as Python IDE

阅读更多

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 complete power 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:

VIM as Python IDE

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 takes away 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 buffer interaction intact.

MiniBuf Explorer

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 to accomplish this task just as well. My favourite one would be TagList . TagList uses Exuberant Ctags for actually generating the tags(note: it really relies on this specific version of ctags - preinstalled implementations on UNIX systems won’t work).

TagList

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 Tasklist reminding the programmer of those lines of code. Tasklist even implements custom lists - to me that’s an incredible productivity gain.

TaskList

In these times, the programmer knows his or her programming language more or less by interactively finding out what it can do. Therefore code completion(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 plugin away) 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.

Omni Completion

Probably the most wanted feature(besides code completion) is debugging graphically. VimPDB is 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.

VimPDB

 

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 see an error message like “E319: Sorry, the command is not available in this 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. Get it 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 TagList and 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 Cygwin with 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 will now be able to use the project view by typing the command :TlistToggle .

Tasklist is 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.

VimPDB is 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.

分享到:
评论

相关推荐

    Python-Pythonmode将Vim变成PythonIDE的一款多合一插件

    Python-mode是针对Vim文本编辑器的一个强大插件,它将Vim转换为一个功能丰富的Python集成开发环境(IDE)。这个插件集成了多种实用功能,以提高Python开发者在Vim中的工作效率。以下是对该插件及其功能的详细说明: ...

    vim-ide.tar.bz2

    Ubuntu 64位免安装版VIM-IDE。 压缩包为直接打包/etc/vim配置及插件包。 root@ubuntu:/etc/vim# tree -L 2 . bundle ale auto-pairs echofunc gdbmgr indentLine LeaderF nerdcommenter nerdtree nerdtree...

    vim-ide.rar_vim IDE

    **vim-ide.rar_vim IDE** 是一个针对程序员的压缩包,主要包含了将经典文本编辑器 Vim 改造为集成开发环境(IDE)的相关资源。这个压缩包特别强调了 Vim 7.2 的中文说明文档以及如何配置 Vim 作为 IDE 的环境。在...

    vim-tmux-focus-events, 使终端vim和tmux更好地协同工作.zip

    vim-tmux-focus-events, 使终端vim和tmux更好地协同工作 tmux-focus-events.vimFocusGained 和 FocusLost 自动命令事件在终端vim中不工作。 这个插件在使用vim内部Tmux时恢复它们。以下是相关内容:vim fugitive插件...

    Python-使用更高效的Vim进行开发

    对于调试Python代码,`vim-python`和`vim-debugger`组合非常有用。它们允许在Vim内直接设置断点、单步执行、查看变量值等。此外,`tagbar`插件可以帮助浏览Python对象的定义,增强代码理解。 在代码质量方面,`ALE`...

    use-vim-as-ide

    在使用Vim作为集成开发环境(IDE)时,它能够提供许多类似IDE的功能,如代码高亮、代码折叠、代码分析、代码开发、工程管理、工具链集成等。下面详细说明这些知识点: 1. 源码安装编辑器 Vim:Vim可以通过源码编译...

    VMware-VIM-all-6.7.0-15976714.txt

    VMware-VIM-all-6.7.0-15976714 原版镜像 .................................................................................................................

    vim-python-logging:Vim 插件为 python-logging 生成的日志着色

    vim-python-日志记录 Vim 插件为生成着色。 当您使用 Vim 打开日志时,它们将如下所示: 对...有用 OpenStack 日志 生成的其他日志 安装 Plugin 'adrienverge/vim-python-logging' git clone ...

    Python-这是一个vim插件允许用户使用vim像googledoc

    1. **安装**:要使用`shrvim`,用户需要首先确保他们的Vim环境已经安装了Python支持,并且安装了像`vim-plug`或`Pathogen`这样的插件管理器。然后,可以通过将`shrvim`的源代码添加到Vim的插件目录或者使用插件管理...

    源码安装 Python-2.7.18

    Linux下 源码安装 Python-2.7.18,解压Python-2.7.18.zip后 [root@RedHatEnterpriseLinux9 ~]# tar -zxvf Python-2.7.18.tgz [root@RedHatEnterpriseLinux9 ~]# cd Python-2.7.18 [root@RedHatEnterpriseLinux9 ~]#...

    Python-Pythonsense是一个Vim插件为Python类方法函数和文档字符串提供文本对象和动作

    Pythonsense不仅独立提供了便捷的Python开发功能,还能与Vim中的其他插件如 syntastic(语法检查)、vim-python-jedi(自动补全)等协同工作,形成一个强大的Python开发环境。 6. **学习与进阶** 对于初学者,...

    Python-Jedivim绑定Vim和Jedi自动补全库对Python进行自动补全

    Plugin 'jedi/vim-jedi' ``` 2. 保存并关闭`vimrc`,然后在Vim中运行: ``` :so ~/.vimrc :PluginInstall ``` 安装完成后,重启Vim,Jedi-vim就已经准备好了。默认情况下,当你在Python文件中输入`.`或`(`时...

    VMware-VIMSetup-all-5.5.0-1312299

    根据提供的文件信息,我们可以推断出这份资料与VMware vCenter Infrastructure Manager (VIM) Setup 5.5.0版本有关。尽管描述部分没有提供太多技术细节,但从标题和其他信息中,我们可以提炼出一系列与VMware ...

    Go-vim-go-Vim的Go开发插件

    **Go-vim-go: Vim的Go开发利器** `vim-go`是Vim编辑器中一个强大的Go语言开发插件,由fatih维护。它为Vim提供了丰富的功能,旨在提升Go程序员的开发效率和代码质量。这个插件包含了调试、语法高亮、自动补全、代码...

    vim的主题space-vim-dark.vim

    vim的主题space-vim-dark.vim

    shades-of-purple.vim:vim的深色主题

    【压缩包子文件的文件名称列表】:"shades-of-purple.vim-master" 表示这是一个Git仓库的主分支克隆,通常包含该主题的所有源代码和配置文件。用户可以通过将这个文件夹复制到Vim的色彩主题目录,或者通过Vim的插件...

    vim-go-ide:Vim作为go语言的IDE将vim打造成go语言的ide

    本文将深入探讨如何将经典的文本编辑器Vim转换为针对Go语言的强大IDE——vim-go-ide。Vim以其高度可定制性和高效的操作方式受到许多程序员的喜爱,而通过安装和配置特定的插件,我们可以将其转变为一个功能完备的Go...

    vim8.0.zip --Linux-CentOS7离线安装VIM及相关依赖包

    vim-8.0.zip gpm-libs-1.20.7-6.el7.i686.rpm ncurses-5.9-14.20130511.el7_4.x86_64.rpm ncurses-base-5.9-14.20130511.el7_4.noarch.rpm ncurses-devel-5.9-14.20130511.el7_4.x86_64.rpm ncurses-libs-5.9-14....

    Python-Syntastic是Vim的一个语法检查插件

    要安装Python-Syntastic,首先确保你的Vim已经安装了`vim-plug`或其他插件管理器。然后在你的`.vimrc`文件中添加以下行来安装和加载插件: ```vim call plug#begin('~/.vim/plugged') Plug 'scrooloose/syntastic' ...

Global site tag (gtag.js) - Google Analytics