Skip to content

Instantly share code, notes, and snippets.

@mhartington
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhartington/07c529ed839e5265263f to your computer and use it in GitHub Desktop.
Save mhartington/07c529ed839e5265263f to your computer and use it in GitHub Desktop.
Emmet.vim function
" Remapping <C-y>, just doesn't cut it.
" This is a bit better and works for
" angular directives or web components
function! s:expand_html_tab()
" try to determine if we're within quotes or tags.
" if so, assume we're in an emmet fill area.
let line = getline('.')
if col('.') < len(line)
let line = matchstr(line, '[">][^<"]*\%'.col('.').'c[^>"]*[<"]')
if len(line) >= 2
return "\<C-y>n"
endif
endif
" go to next item in a popup menu.
" this will insert a snippet if it's selected in the menu
" due to neosnippets being the first check.
if pumvisible()
return "\<C-n>"
endif
" expand anything emmet thinks is expandable.
" I'm not sure anything happens below this block.
if emmet#isExpandable()
return "\<C-y>,"
endif
" return a regular tab character
return "\<tab>"
endfunction
autocmd FileType html imap <buffer><expr><tab> <sid>expand_html_tab()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment