ropevim: vim, one step closer to and IDE
Every vim user, at some point requires the functionality that is well-known from “big” IDEs. A lot of people stop at built-in capabilities, like keyword completion seen in opened buffers, built-in got-to-definition etc. which are limited by their attempt to be universal. In this post I’ll take a look at the tool, designed for working on python code and at the same time providing means of “smart” autocomplete, jumping to identifier’s definition etc.
My own interpretation of rather laconic documentation follows.
Installation
First of all we’ll need python-enabled vim. For gentoo - type:
# USE=python emerge app-editors/vim app-vim/vimpython
Next — installing the rope library and corresponding scripts. For this — get sources from mercurial repository (following is assuming you put sources under /usr/src):
/usr/src $ hg clone http://bitbucket.org/agr/rope
/usr/src $ hg clone http://bitbucket.org/agr/ropemode
/usr/src $ hg clone http://bitbucket.org/agr/ropevim
or download snapshots — http://rope.sf.net/hg/rope/archive/tip.tar.gz + http://rope.sf.net/hg/ropemode/archive/tip.tar.gz + http://rope.sf.net/hg/ropevim/archive/tip.tar.gz .
First of all — install rope:
/usr/src/rope $ sudo python setup.py install
next — install ropevim:
/usr/src/ropevim $ ln -s ../ropemode/ropemode
/usr/src/ropevim $ sudo python setup.py install
At this point the library is installed and configuring vim starts.
Настройка
To use all of ropevim’s abilities you have to load it, and refering to README.txt, there are two methods of doing this:
-
load in ~/.vimrc (
echo "source /usr/src/ropevim/ropevim.vim" >> ~/.vimrc) -
copy to ~/.vim/plugins —
ln -s /usr/src/ropevim/ropevim.vim ~/.vim/plugins
The last thing to do is to add let ropevim_vim_completion=1 to ~/.vimrc. Now you can use this tool. For testing you can load some python code, put cursor to some place, appropriate for completion and in insert mode do <C-R>=RopeCodeAssistInsertMode(). As a result you should get prompt to enter path to the root of current project, (e.g. “.”). After this rope performs indexing current project’s files and immediately offers completion alternatoves. Works? Cool. Now we can bind this to the shortcut, for example:
function! TabWrapperRope()
if strpart(getline('.'), 0, col('.')-1) =~ '^\s*$'
return "\<Tab>"
else
return "\<C-R>=RopeCodeAssistInsertMode()\<CR>"
endif
endfunction
imap <Tab> <C-R>=TabWrapperRope()<CR>
Now we have rather pretty completion and responsible enough code completion.
Of course, library’s abilities don’t end here, but only start. I will not describe everything, that it can do, and only list some of the most often-used functions with their default keybindings. All commands are separated into logical groups: for managing projects, refactoring, code-assist. Their hot key-combinations start with C-x p, C-c r, C-c r a respectively. Sequences of three or four keys are obviously not the most comfortable way of performing these actions, so there are shorter combinations for some functions out-of-the-box. According to README.txt they look like:
================ ============================
Key Command
================ ============================
M-/ RopeCodeAssist
M-? RopeLuckyAssist
C-c g RopeGotoDefinition
C-c d RopeShowDoc
C-c f RopeFindOccurrences
================ ============================
Among rope‘s functions I can mention: ranaming variables, modules, analising and managing imports, displaying function’s/method’s documentation and others.
So, making vim one step closer to bigger brothers we make sure that expanding this editor’s functionality is only limited by developers’ imagination.
Links:




Comments
The autocompletion is significantly worse than that available with with stock vim omni completion and SuperTab plugin:
let g:SuperTabDefaultCompletionType = “context”
With SuperTab and vanilla omni completion I get:
mymodel.objects.fi[tab]: filter(…,*)
and I see a pydoc for “filter” in a window above.
With ropevim and your method, I get:
mymodel.objects.fi[tab]: frontend settings.py default settings.py etc..
All of these are not part of mymodel.objects and there’s no docstring visible.
Very disappointing :(
Полезная информация, спасибо за столь подробное описание.
Comment form for «ropevim»