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:
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.
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).
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.
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.
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.
–
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-mode:将 Vim 变成 Python IDE 的一款多合一插件
Ubuntu 64位免安装版VIM-IDE。 压缩包为直接打包/etc/vim配置及插件包。 root@ubuntu:/etc/vim# tree -L 2 . bundle ale auto-pairs echofunc gdbmgr indentLine LeaderF nerdcommenter nerdtree nerdtree...
Python-使用更高效的Vim进行开发
vim-tmux-focus-events, 使终端vim和tmux更好地协同工作 tmux-focus-events.vimFocusGained 和 FocusLost 自动命令事件在终端vim中不工作。 这个插件在使用vim内部Tmux时恢复它们。以下是相关内容:vim fugitive插件...
Vi Improved-----Vim 最全面的vim使用教程,全书共17章,从浅入深介绍Vim的使用,满足不同层次的使用者的要求。
vim7.2中文说明文档+vim ide环境配置......
vim-handbook-cn-71(vim中文手册) vim-handbook-cn-71(vim中文手册) vim-handbook-cn-71(vim中文手册)
Atom-atom-vim-mode-plus.zip,vim-mode improvedVIM模式增强,atom是一个用web技术构建的开源文本编辑器。
完整版《像使用IDE一样使用VIM》,高清,带目录。希望对你们有用
vim-python-日志记录 Vim 插件为生成着色。 当您使用 Vim 打开日志时,它们将如下所示: 对...有用 OpenStack 日志 生成的其他日志 安装 Plugin 'adrienverge/vim-python-logging' git clone ...
vim-go-ide:Vim作为go语言的IDE将vim打造成go语言的ide
VMware-VIM-all-6.7.0-15976714 原版镜像 .................................................................................................................
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....
vim的主题space-vim-dark.vim
vim-colors-solarized, vim文本编辑器的精确 colorscheme 标题描述作者创建的颜色已经修改用于Vim的Solarized colorscheme机器和人员的精确颜色Schoonover浅黄色2011 152011年 16用于Vim的 Solarized colorsche
vim-textobj-user, Vim插件 vim-textobj-user---创建你自己的文本对象 vim-textobj-user是一个用于创建你自己的文本对象而不用痛苦的Vim插件。 因为要处理许多错误,所以很难创建文本对象。 这个插件隐藏了这样的...
Pythonsense是一个Vim插件,为Python类,方法,函数和文档字符串提供文本对象和动作
python-vim这是我自己精简后的python vim开发包环境。实还有更加丰富的功能,但那只会让vim速度变得很慢。 所以我要说的是,并不是插件越多越好,而是越精简越好,把不用的插件都在.vimrc中注释掉。更多的介绍python...
vim-go - Vim的Go开发插件