2

How can I move (navigate) between Markdown ATX-style headers?

The Vim plugin https://github.com/gbgar/pandoc-sections.vim does so using the [ and ] keys, but only when there is no space between the opening # hashes and the header text.

Unfortunately, above plugin is no longer maintained and the now more common space between the opening # hashes and the header text is not supported.

The solution could be as easy as forking the plugin and extending the regex's in https://github.com/gbgar/pandoc-sections.vim/blob/master/ftplugin/pandoc/pandoc-sections.vim However, my attempts at successfully extending the regex's were in vain.

0

1 Answer 1

2
+50

The linked plugin gives the following regexs (modified to only include #-relevant parts):

^\s*#\a.*\n
^\s*#\{2,6}.*\n

The first requires an alphabetic character (/\a) after the #; the second does not (.*). So you could take at least the function PandocSectionMovement and keybindings if you modify the first regex to

^\s*#.*\n

Do be warned that this might catch comments in embedded code, like in the following snippet of markdown:

```bash
# this is a comment
```

You might be able to work-around that by passing {skip} to search like

" 0 stopline, timeout is like not passing a value
call search(s:movpattern, l:sflag, 0, 0,
      \ {-> synID(line('.'), col('.'), 0)->synIDattr('name') !~# 'markdownH\d'})

At, least, this worked for me on a test file with sh-like comments.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.