I recently stumbled across a handy tutorial on configuring a Drupal dictionary in Vim for autocomplete. I also remembered helping a friend out with a similar problem, Drupal syntax highlighting for Nano. I then combined the two and have a simple to follow tutorial for generating your own drupal 6 dictionary for vim autocomplete!
Step 1… Create a dictionaries folder if you don't already have one…
mkdir -p ~/.vim/dictionaries/
Step 2… Generate your dictionary… Run the following from your Drupal install…
grep "^function" modules/ includes/ -hR | gawk '{ sub(/\(.+/, "(", $2); print $2 }' | sort -u > ~/.vim/dictionaries/drupal6.dict
This will search the modules and includes folders recursively for all lines starting with "function". Then, via some gawk
and tr
magic, we end up with a list of functions that will be dumped into our dictionary file!
Step 3… Configure Vim to add the new dictionary file on load up…
vim ~/.vimrc
then add…
set dict +=~/.vim/dictionaries/drupal6.dict
Step 4… There is no step 4. You're done!
When editing your code (in INSERT mode), press Ctrl+X and then Ctrl+K to invoke the auto-complete menu.
Brilliant :-)