Skip to content

Instantly share code, notes, and snippets.

@dahu
Created August 17, 2012 20:14
Show Gist options
  • Select an option

  • Save dahu/3382218 to your computer and use it in GitHub Desktop.

Select an option

Save dahu/3382218 to your computer and use it in GitHub Desktop.
Toggle display of current div in statusline
let s:orig_statusline = &statusline
function! HTMLCurrentDivId()
let m = searchpos('<\s*div.\{-}id\s*=\s*"\([^"]*\)"', 'bnWp')
if m[2] == 2
return matchlist(getline(m[0]), 'id\s*=\s*"\([^"]*\)"')[1]
else
return ''
endif
endfunction
function! ToggleStatusLineCurrentDiv()
if s:orig_statusline == &statusline
let statusline = &statusline.' \%{HTMLCurrentDivId()}'
else
let statusline = s:orig_statusline
endif
exe "set statusline=".escape(statusline, ' ')
endfunction
nnoremap <silent> <leader>x :call ToggleStatusLineCurrentDiv()<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment