" Pulls in Drupal variables (from Drush) and outputs variable_set() calls for
" each variable.
" Todo: Should probably check to see if drush can bootstrap
function! s:DrushVariableGet(args)
  exec "normal o"
  exec "r !drush variable-get --pipe " . a:args . " | sed 's/$variables\\[\\(.*\\)\\] = /variable_set(\\1, /' | sed 's/;$/);/'"
  exec "normal ={"
command! -bang -nargs=* -complete=file Dvar call s:DrushVariableGet(<q-args>)

Often times when I'm writing hook_update functions, I want to create variable_set() calls to setup variables (especially when installing and configuring new modules). This Vim function makes that easy:

  • Make sure your Vim instance is running within a Drupal environment (so Drush can run)
  • Execute the following command:

:Dvar <variable_name>

  • This will output:

variable_set('<variable_name>', '<current_variable_value>');

  • You can even run it for multiple variable matches, e.g. :Dvar user_picture will output:

variable_set('user_pictures', '0'); variable_set('user_picture_path', 'pictures'); variable_set('user_picture_default', ''); variable_set('user_picture_dimensions', '85x85'); variable_set('user_picture_file_size', '30'); variable_set('user_picture_guidelines', '');