Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I have this in my current vimrc.
iabbr Hook <C-R>=HookFunc()<CR>
" HookFunc(): Drupal helper function
function! HookFunc()
let f = strpart(expand("%:t"), 0, stridx(expand("%:t"), '.', 0))
" wtf?
let a = input("")
let h = input("Which hook? ")
return "/**\<CR>Implements hook_" . h . "()\<CR>/\<CR>" . "function " . f . "_" . h . "() {\<CR>}\<ESC>k%i"
endfunction
It definitely needs some improvement, for example I have no idea why I need two inputs to get the hook name, and for some reason this interferes with the correct indentation of the function comment. But I find it helpful. Would there be interest in including this?
Credit goes to Bitkid for writing the original code, that I've since modified and messed up ;)
Comments
Comment #1
rodrigoaguileraIs not this what snippets are for?