
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 :-)










6 Comments
color me impressed
This is very very cool!
Thank you so much! I exclusively use vim (because I just can't get around all those graphical IDEs) and this will help a lot!
Am I missing something?
Could a similar (perhaps better) result be achieved using exuberant CTags? As described in this presentation - http://zmievski.org/2007/02/vim-for-php-programmers-slides-and-resources.
Apologies if I'm missing something - still pretty new to Vim.
this is great. thanks for
this is great. thanks for sharing.
is there a way to include the parameters of a function as well? for example the link function takes: l($text, $path, $options = array()).
obviously your script could be updated to include this, but is there a way to get it working with the vim dictionary? i tried this manually but inserting parameters for a function in the dictionary file and it didn't work. i'm new to vim so imagine that the dictionary is limited to the function name but don't know. i'll keep looking and post if i find anything. in the meantime any insight would be appreciated. thanks.
For Windows users, here's
For Windows users, here's something you can use in Notepad++ (last post has my latest files),
http://drupal.org/node/326803
Preview:
ScreenShot
Enjoy!,
Arian
How to switch between drupal
How to switch between drupal 6 and 7
That's a good question; I'd
That's a good question; I'd be inclined to map to a different key combination as an easy fix.
Add new comment