Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from monnand/master

Jump to reference
  • Loading branch information...
commit b764272f5517235d82d70f64cea777061052680d 2 parents 948c411 + 950b8d5
@spf13 authored
Showing with 65 additions and 0 deletions.
  1. +65 −0 ftplugin/markdown.vim
View
65 ftplugin/markdown.vim
@@ -16,4 +16,69 @@ setlocal expandtab
let b:undo_ftplugin .= "|setl cms< com< fo<"
+let s:jumpList = []
+
+function MarkdownJumpRef()
+ let line = getline('.')
+ let curcol = virtcol('.')
+ let start = curcol - 1
+ let end = curcol - 1
+
+ while start >= 0
+ if line[start] == '['
+ break
+ endif
+ let start = start - 1
+ endwhile
+
+ while end < strlen(line)
+ if line[end] == ']'
+ break
+ endif
+ let end = end + 1
+ endwhile
+
+ if line[start] != '[' || line[end] != ']'
+ return -1
+ endif
+
+ let ref = strpart(line, start + 1, end - start - 1)
+ let ref = "^\\[" . ref . "\\]:"
+ let pos = getpos('.')
+ let linenon = search(ref)
+ let npos = getpos('.')
+
+ if pos != npos
+ let s:jumpList = add(s:jumpList, pos)
+ endif
+
+ let line = getline('.')
+
+ let c = 0
+ while c < strlen(line)
+ if line[c] == ':'
+ break
+ endif
+ let c = c + 1
+ endwhile
+
+ let npos[2] = c + 2
+ call setpos('.', npos)
+ return 0
+endfunction
+
+function MarkdownJumpBack()
+ let l = len(s:jumpList)
+ if l <= 0
+ return
+ endif
+ let pos = s:jumpList[l - 1]
+ let s:jumpList = s:jumpList[:l - 2]
+
+ call setpos('.', pos)
+endfunction
+
+map <C-]> :call MarkdownJumpRef()<CR>
+map <C-T> :call MarkdownJumpBack()<CR>
+
" vim:set sw=2:
Please sign in to comment.
Something went wrong with that request. Please try again.