Skip to content

Instantly share code, notes, and snippets.

@dirkk
Created November 21, 2012 10:17
Show Gist options
  • Save dirkk/4124117 to your computer and use it in GitHub Desktop.
Save dirkk/4124117 to your computer and use it in GitHub Desktop.
How to do nice XQuery coding in vim
1. Install Exuberant Ctags
2. Create ~/.ctags with the following content to (rudimentary) support XQuery for ctags:
--langdef=xquery
--langmap=xquery:.xq.xqm.xqy
--regex-xquery=/^[ \t]*declare?[ \t]*(%[^%])*[ \t]*function[ \n\t]*([_a-zA-Z0-9:-]*:)?([_a-zA-Z0-9-]+)/\3/f,function/
--regex-xquery=/^[ \t]*declare[ \t]*variable[ \t]*\$([_a-zA-Z0-9:-]*:)?([_a-zA-Z0-9-]+)/\2/v,variable/
--regex-xquery=/^module namespace[ \t]*(\w+)[ \t]*=.*/\1/m,module/
3. Install the Tlist vim plugin: vim-taglist.sourceforge.net
4. Append to your .vimrc:
let tlist_xquery_settings = 'xquery;f:function;v:variable;m:module'
set tags=./tags;
5. Do some nice keymapping to not have a knot in your fingers...
nmap <F3> :TlistToggle<cr>
nmap <F4> :TlistAddFilesRecursive . *.xq*<cr>
nmap <F5> g<C-]>
This opens using F3 the Tlist view, where you see your different functions, variables and modules. This displays just the stuff for your files within your vim buffer (i.e. your currently opened files). If you want to add all files recursively starting from the current directory, press F4.
When you select in normal mode a function name, pressing F5 will go to the function definition. If there are multiple possible locations, you will be presented a selection box.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment