Replicate Textmate html editor's code completion functionality in ViM with the close tag plugin

|
Being a long time Vim user I have rarely been enticed by another source editor as Vim really is the Swiss army knife of editors. I was surprised when trying out Textmate to find that it really does make editing HTML and code much easier with its range of auto code completion rules. My problem comes from HTML and XML's need to close tags, which when compared to programming languages, are quite verbose. Closing tags are hard to type because they require the use of the shift key for both the start and the end of the tag. Whereas most programming languages will allow you to close with just a } or end.

Pure HTML editors like Dreamweaver do solve the problem with their auto tag closing however Dreamweaver is limited by its focus on web page, and some web application, development environment. Textmate on the other hand appears to take a finely balanced approach between offering time saving automation and high extendability. But Vim, being the king (in my humble opinion anyway) of extensible text editors does have a plugin that allows users that want to utilize it as a great free HTML editor to benefit from the automated code completion offered by others.

The solution lies in the closetag.vim plugin written by Steven Mueller. The plugin is not fully automatic like previously mentioned HTML editors but it does offer the same functionality when the [ctrl]-_ (underscore) keys are pressed. I personally find this to be a better solution than another auto tag closer I found previous, which would have issues with code formatting. Using closetag means I can have the cursor where I needed then just press the mapped keys to close off whatever HTML section I was working on.

To install the plugin simply download the file and place it in your ~/.vim/scripts directory; which you may need to create. Then just include the following line to your ~/.vimrc file.

:au Filetype html,xml,xsl source ~/.vim/scripts/closetag.vim
For Cake PHP coders just add ,ctp to the end of html,xml,xsl. Other file types can also be added the same way.

0 comments:

Post a Comment