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

rodrigoaguilera’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)

Is not this what snippets are for?