I'm using python day to day and need to have an index of both my local project and every python module / egg found in my virtualenv
The below is a half working version of what I would like to see improved. Currently I can do one OR the other before the redraw command. With this approach I end up with a single .ctags file in the root of each project I work on and vim is aware making any lookup by class name/method name/etc quick and easy.
Is there a way to combine those 2 exe lines into a single line that still results in just one index file?
thank you in advance
set tags=./.ctags,.ctags;
" re-index the ctags file
map <leader>ri :call RenewTagsFile()<cr>
" search through the indexed ctags file for any class/method/etc
map <leader>fs :FufTag<CR>
function! RenewTagsFile()
exe 'silent !ctags -Rf .ctags ' . system('python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"')''
exe 'silent !ctags -Rf .ctags --extra=+f --exclude=.git --languages=-javascript 2>/dev/null'
exe 'redraw!'
endfunction
UPDATE
For anyone who might stumble upon this question in the future I was able to append using the -a flag (so the renew tags file function would look like this instead)
function! RenewTagsFile()
exe 'silent !ctags -Rf .ctags ' . system('python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"')''
exe 'silent !ctags -a -Rf .ctags --extra=+f --exclude=.git --languages=-javascript 2>/dev/null'
exe 'redraw!'
endfunction
You don’t need to. Vim is able to work with multiple tags files, just choose one location to place virtualenv tags file and include full path to it into 'tags' option.
There is another possibility though: read man ctags
. It is possible to make ctags add tags to an existing file by adding one switch. You still don’t need to combine these commands into one command.
Note: there are some strange things in your code:
set tags=./.ctags,.ctags;
Do you really need to include .ctags;
file with semicolon? Guess it is a typo.
map …
nnoremap …
. First, there is nothing here you want to be remapped hence nore
. Second, commands are not written to work from visual mode and I doubt you need them in operator-pending mode hence nnore
.
exe 'silent !ctags -Rf .ctags --extra=+f --exclude=.git --languages=-javascript 2>/dev/null'
exe 'redraw!'
You don’t need :exe
at all here, just
silent !ctags -Rf .ctags --extra=+f --exclude=.git --languages=-javascript 2>/dev/null
redraw!
. But you can completely avoid :redraw!
by using system()
:
call system('ctags -Rf .ctags ' . system('python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"'))
call system('ctags -Rf .ctags --extra=+f --exclude=.git --languages=-javascript 2>/dev/null')