From 64b0fabd853d0e838bddb9645e92d41413e63e61 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 23 Jun 2019 23:06:08 +1200 Subject: Replace existing Markdown heading underlines --- vim/autoload/markdown.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vim/autoload/markdown.vim b/vim/autoload/markdown.vim index c0818246..8bac8045 100644 --- a/vim/autoload/markdown.vim +++ b/vim/autoload/markdown.vim @@ -11,8 +11,13 @@ function! markdown#Heading(char) abort " heading text let underline = repeat(a:char, strlen(heading)) - " Append the heading text to the buffer on a new line after the heading - call append(pos[1], underline) + " If the line after this one looks like it's already an underline, replace + " it; otherwise, create a new underline + if getline(pos[1] + 1) =~# '^[-=]\{2,}$' + call setline(pos[1] + 1, underline) + else + call append(pos[1], underline) + endif " Move to the first column of the underline we just inserted let pos[1] += 1 -- cgit v1.2.3