From 67fd74440670dfc1cc8c03b0cd991961904347c5 Mon Sep 17 00:00:00 2001 From: Samy Kamkar Date: Sun, 2 Aug 2020 15:36:35 -0700 Subject: [PATCH 1/2] Add function return header for statusline --- README.md | 10 ++++++++++ ftplugin/markdown.vim | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/README.md b/README.md index a3197253..fe858135 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](#commands) 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. " From 4593626a01024751cde4e43fa53bf7dc17299086 Mon Sep 17 00:00:00 2001 From: Samy Kamkar Date: Sun, 2 Aug 2020 15:37:41 -0700 Subject: [PATCH 2/2] Fix toc --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fe858135..a0b33bbb 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Syntax highlighting, matching rules and mappings for [the original Markdown](htt 1. [Options](#options) 1. [Mappings](#mappings) 1. [Commands](#commands) -1. [Functions](#commands) +1. [Functions](#functions) 1. [Credits](#credits) 1. [License](#license)