Simon Jackson wrote:
how do i tell vim to close html tags as i'm writing them and place the
cursor in between the 2 tags?

example:

if i type..
<p>

then vim replaces it with
<p></p>

and places my cursor should be between '>' and '<'


To do exactly that, you would have to write, probably, an insert-mode mapping for the > key (local-to-buffer, probably in $HOME/.vim/after/ftplugin/html.vim [Unix], or $HOME/vimfiles/after/ftplugin/html.vim [Windows]).

However, there are already two preprogrammed methods to close HTML tags:

Method I: Using omni completion (Vim 7 only).

In an HTML file, when you enter <\ then hit Ctrl-X Crtl-O in Insert mode, Vim will offer to insert the closing tag for the latest not-yet-closed tag.

Method II: Using closetag.vim http://vim.sourceforge.net/scripts/script.php?script_id=13 (also in Vim 6).

Download the closetag.vim script from Vim-online, then source it at the FileType autocommand event for the html (xml, etc.) filetype: e.g. in the after-plugin mentioned in my first paragraph above. Then Ctrl-_ (control-underscore) will close the latest not-yet-closed tag. Self-closed <tags /> are ignored, as well as (in HTML) a configurable set of unpaired and optionally-paired tags.

Method I does not require installing anything additional to the standard Vim distribution, but Method II is IMHO easier to use.


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
47. You are so familiar with the WWW that you find the search engines useless.

Reply via email to