edit koha code with vim

Par mc, 27 juin 2009 18 h 51 min

Using a terminal based editor is cool: you can remotely edit the code on our server and share your screen to make a collaborative work session with someone elsewhere (screen -xS koha). But some claims that they work faster with IDEs. I want to share my tips for koha editing.

[color=blue]always from the koha root[/color]

When i start a koha devel session, i change directory to koha root and update the code and refresh the tags

cd ~/src/koha
git pull --rebase
ctags --languages=perl -R -f TAGS

[color=blue]tags[/color]

If you don’t know about tags: this is an amazing way to navigate into the code:

- goto a function call (cursor under the function name)
- split the window ( <c-w>f )
- call the tag ( <c-]> )

you have now 2 windows: one on the function call, one on the function def.
you can go to any other tag: type :tag Add<tab> to see all koha functions begining by tags.

tags can also be used to complete the code: in insertmode, type Add<c-x]> and choose the function name in the menu.

[color=blue]open templates[/color]

this is my ~/.vim/plugin/koha. it provides easy way to access to a template or include:

- drive the cursor over the name of the template
- in normal mode, type ,to (template open).
- ensure it’s the good template name
- type enter
- et voila …

" if vim is in a koha root
if isdirectory('C4')
	let g:koha_itmpl='koha-tmpl/intranet-tmpl/prog/en/modules' " intranet templates
	let g:koha_iinc='koha-tmpl/intranet-tmpl/prog/en/includes' " intranet includes
 
	" ,te: template edit: just prepare :e with correct path to template root 
	" ,to; template open: just prepare :e with correct path to the template
	" under the cursor
	" ,ie and ,io are the same for includes 
	nnoremap ,te :e <c-r>=g:koha_itmpl<cr>
	nmap ,to ,te/<c-r><c-f>
	nnoremap ,ie :e <c-r>=g:koha_iinc<cr>
	nmap ,io ,ie/<c-r><c-f>
 
	" add include in the path ... so gf works inside templates
	exec 'set path+='.g:koha_iinc
endif

[color=blue]edit templates[/color]

this is my ~/.vim/plugin/html_template.vim

inoremap <V <!-- TMPL_VAR NAME="" --><c-o>F"
inoremap <L <!-- TMPL_LOOP NAME="" --><!--/TMPL_LOOP --><c-o>F"
inoremap <I <!-- TMPL_IF X><!-- /TMPL_IF --><esc>FXs
inoremap <U <!-- TMPL_UNLESS X><!-- /TMPL_UNLESS --><esc>FXs
inoremap <EI <!-- TMPL_ELSIF NAME="" --><c-o>F"
inoremap <EL <!-- TMPL_ELSE -->
inoremap <# <!-- TMPL_INCLUDE NAME="" --><c-o>F"

now, in insert mode: type <V or <I or ..

et voila

HTH

Related posts:

  1. navigate into koha code with vim
  2. add js behaviors to koha
  3. Arborescence Django
  4. Arborescence Django
  5. Dance, Koha, dance !

n commentaire à “edit koha code with vim”

  1. Tinybox dit :

    [...] Related posts:edit koha code with vim [...]

Laisser un commentaire

Panorama Theme by Themocracy