Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow getting markdown header #532

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions ftplugin/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"
Expand Down