initial commit
This commit is contained in:
commit
540380cb71
2 changed files with 83 additions and 0 deletions
40
README.md
Normal file
40
README.md
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
# vim-markdown-navigation
|
||||||
|
|
||||||
|
Enable navigation of in-document links in Vim editor for Markdown documents.
|
||||||
|
|
||||||
|
This plugin is intended to work in conjunction with [vim-markdown](https://github.com/plasticboy/vim-markdown) but will work standalone as well.
|
||||||
|
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Copy markdown.vim to ~/.vim/after/ftplugin/
|
||||||
|
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
A useful document to test this with is [README.md with TOC](https://github.com/ekalinin/envirius/blob/24ea3be0d3cc03f4235fa4879bb33dc122d0ae29/README.md) by ekalinin
|
||||||
|
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Simply move the cursor over a link and press *K* (shift-k).
|
||||||
|
|
||||||
|
|
||||||
|
## Recommended
|
||||||
|
|
||||||
|
For convenient generation of tables of contents for Markdown documents the following are recommended:
|
||||||
|
|
||||||
|
[vim-markdown-toc](https://github.com/mzlogin/vim-markdown-toc) - Vim plugin capable of generating tables of contents in GitHub, GitLab, and Redcarpet flavored markdown.
|
||||||
|
|
||||||
|
[github-markdown-toc](https://github.com/ekalinin/github-markdown-toc.go) - Standalone program with many features that generates tables of contents.
|
||||||
|
|
||||||
|
|
||||||
|
## Authors
|
||||||
|
|
||||||
|
User *novum* on freenode IRC channel #vim
|
||||||
|
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
|
||||||
|
All of the helpful people on the freenode #vim channel.
|
||||||
|
|
43
after/ftplugin/markdown.vim
Normal file
43
after/ftplugin/markdown.vim
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
" this script (markdown.vim) must be placed in ~/.vim/after/ftplugin
|
||||||
|
" requires https://github.com/plasticboy/vim-markdown
|
||||||
|
|
||||||
|
function! s:markdownGotoHeader()
|
||||||
|
let pos = getpos('.')
|
||||||
|
call search('(', 'bcW', line('.'))
|
||||||
|
if !search('#', 'cW', line('.'))
|
||||||
|
echohl ErrorMsg
|
||||||
|
echo 'No link found on rest of line'
|
||||||
|
echohl NONE
|
||||||
|
call setpos('.', pos)
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
let asav = @a
|
||||||
|
normal! "ayib
|
||||||
|
let targ = @a
|
||||||
|
let @a = asav
|
||||||
|
let targ = substitute(targ, '^#\+', '', '')
|
||||||
|
let targ = substitute(targ, '^\s\+\|\s\+$', '', 'g')
|
||||||
|
if empty(targ)
|
||||||
|
echohl ErrorMsg
|
||||||
|
echo 'target is empty'
|
||||||
|
echohl NONE
|
||||||
|
call setpos('.', pos)
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
let targ = split(targ)[0]
|
||||||
|
let targ = '\[[:punct:][:space:]]\*'.join(map(split(targ, '-'), { _,str -> join(map(split(str, '\zs'), { _,chr -> chr == '\' ? '\\' : chr }), '\[[:punct:]]\*') }), '\[[:punct:][:space:]]\+').'\[[:punct:][:space:]]\*'
|
||||||
|
let pat = '\V\c\^\%(\s\*'.targ.'\n\[-=]\|#\+\s\*'.targ.'\)'
|
||||||
|
let lnr = search(pat, 'cnw')
|
||||||
|
if lnr == 0
|
||||||
|
echohl ErrorMsg
|
||||||
|
echo 'target /'.targ.'/ not found'
|
||||||
|
echohl NONE
|
||||||
|
call setpos('.', pos)
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
call setpos("''", pos)
|
||||||
|
call setpos('.', [bufnr(), lnr, 1, 1])
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
nnoremap <buffer> <silent> K :call <sid>markdownGotoHeader()<cr>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue