I don't know if this is possible, but does anyone know of an indent script that will support this scenario?
(| is cursor)
given
<div>|<div>
if I press enter, I want to see
<div>
|
</div>
instead of
<div>
|<div>
I don't know if this is possible, but does anyone know of an indent script that will support this scenario?
(| is cursor)
given
<div>|<div>
if I press enter, I want to see
<div>
|
</div>
instead of
<div>
|<div>
delimitMate will take care of this for you. You will however, need two additional settings...
add the >:< pair to the list of html files:
au FileType html let delimitMate_matchpairs = "(:),[:],{:},>:<"
and tell it what pattern you'd like to add after inserting a
au FileType html let b:delimitMate_expand_cr = "\<CR>\<CR>\<Up>\<Tab>"
(this will, instead of inserting two a , insert two s, press up, then insert a tab)
You could do something like this:
function! NewlineInTag()
let lnum = getline('.')
let cnum = col('.')
let chars = strpart(lnum, cnum - 2, 2)
if chars =~ '><'
return "\<CR>\<ESC>\<UP>$o"
else
return "\<CR>"
endif
endfunction
imap <CR> <C-R>=NewlineInTag()<CR>
Ended up going with brian Carpers answer, only modified very slightly
"fancy html indenting
function! NewlineInTag()
let lnum = getline('.')
let cnum = col('.')
let chars = strpart(lnum, cnum - 2, 3)
if chars =~ '></'
return "\<CR>\<ESC>\<UP>$o"
else
return "\<CR>"
endif
endfunction
autocmd FileType eruby,html imap <CR> <C-R>=NewlineInTag()<CR>