diff --git a/README.md b/README.md index a3197253..a0b33bbb 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Syntax highlighting, matching rules and mappings for [the original Markdown](htt 1. [Options](#options) 1. [Mappings](#mappings) 1. [Commands](#commands) +1. [Functions](#functions) 1. [Credits](#credits) 1. [License](#license) @@ -447,6 +448,15 @@ The main contributors of vim-markdown are: If you feel that your name should be on this list, please make a pull request listing your contributions. +## Functions + +- `g:MarkdownGetHeader`: + + Returns the full, current header line. Useful to add to statusline, for example if using [airline](https://github.com/vim-airline/vim-airline) +``` +let g:airline_section_gutter = '%= %{exists(''*MarkdownGetHeader'')?MarkdownGetHeader():""}' +``` + ## License The MIT License (MIT) diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim index d6e51c21..bb07a509 100644 --- a/ftplugin/markdown.vim +++ b/ftplugin/markdown.vim @@ -63,6 +63,14 @@ let s:levelRegexpDict = { " let s:headersRegexp = '\v^(#|.+\n(\=+|-+)$)' + +" Returns full header line if there is one +" +function! g:MarkdownGetHeader() + return getline(s:GetHeaderLineNum()) +endfunction + + " Returns the line number of the first header before `line`, called the " current header. "