I most IDEs and modern text editors (Sublime Text 3) the cursor is correctly indented after inserting a newline in between an html tag (aka \'expanding\" the tag):
B
This little snippet will remap Enter in insert mode to test whether or not the cursor is between >
and <
and act accordingly if it is. Depending on your indent settings the \
may need to be removed.
It will not play nice with other plugins that might be also be mapping the Enter key so be aware that there is probably more work to do if you want that compatibility.
function EnterOrIndentTag()
let line = getline(".")
let col = getpos(".")[2]
let before = line[col-2]
let after = line[col-1]
if before == ">" && after == "<"
return "\\O\"
endif
return "\"
endfunction
inoremap EnterOrIndentTag()
I have only tested the simple cases (beginning of the line, end of the line, inside and outside of ><
), there are probably edge cases that this would not catch.