All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 "TODO get working on visual mode
4 " goes to the nearest head before current position
5 " returns its initial hashes (#)
7 " goes to beginning of document
9 fu! b:Markdown_GoCurHeader()
10 if search( '^#', 'bcW' ) != 0
11 return matchstr( getline('.'), '\v^#+' )
14 ec 'outside any header'
19 "same as `b:Markdown_GoCurHeader`:function: but does not change cursor position
20 fu! b:Markdown_GetHashesCurHeader()
21 let line = search( '\v^#', 'nW' ) != 0
22 retu matchstr( getline(line) '\v^#+' )
25 "goes to next header of any level
27 fu! b:Markdown_GoNextHeader()
28 if search( '\v^#', 'W' ) != 0
29 return matchstr( getline('.'), '\v^#+' )
37 "goes to previous header of any level
39 "if there is no previous header, only print a warning
41 "if the cursor is not exactly at the header,
42 "it goes to exactly the header. So this could be used
43 "if you want to go to the current header line.
44 fu! b:Markdown_GoPreviousHeader()
45 if search( '^#', 'bW' ) != 0
46 return matchstr( getline('.'), '\v^#+' )
54 "if already at top level, go to beginning of buffer
55 fu! b:Markdown_GoHeaderUp()
56 let l:hashes = b:Markdown_GoCurHeader()
57 if len( l:hashes ) > 1
58 cal search( '^' . l:hashes[1:] . '[^#]', 'b' )
64 fu! b:Markdown_GoNextHeaderSameLevel()
66 let l:hashes = b:Markdown_GoCurHeader()
68 "go to next occurrence of that number of hashes
69 cal search( '^' . l:hashes . '[^#]', 'W' )
73 "if no more next siblings, print error message and do nothing.
74 fu! b:Markdown_GoNextSiblingHeader()
76 let l:hashes = b:Markdown_GoCurHeader()
82 let l:nhashes = len(l:hashes)
84 "special case, just add the largest possible value
85 let l:nextLowerLevelLine = line('$') + 1
87 let l:nextLowerLevelLine = search( '\v^#{1,' . ( l:nhashes - 1 ) . '}[^#]' , 'nW' )
90 let l:nextSameLevelLine = search( '\v^' . l:hashes . '[^#]', 'nW' )
93 \ l:nextSameLevelLine > 0
96 \ l:nextLowerLevelLine == 0
98 \ l:nextLowerLevelLine > l:nextSameLevelLine
101 cal cursor( l:nextSameLevelLine, 0 )
103 ec 'no more siblings'
108 fu! b:Markdown_GoPreviousHeaderSameLevel()
110 let l:hashes = b:Markdown_GoCurHeader()
112 "go to next occurrence of that number of hashes
113 cal search( '^' . l:hashes . '[^#]', 'bW' )
117 "if no more next siblings, print error message and do nothing.
118 fu! b:Markdown_GoPreviousSiblingHeader()
120 let l:hashes = b:Markdown_GoCurHeader()
126 let l:nhashes = len(l:hashes)
128 "special case, just add the largest possible value
129 let l:prevLowerLevelLine = -1
131 let l:prevLowerLevelLine = search( '\v^#{1,' . ( l:nhashes - 1 ) . '}[^#]' , 'bnW' )
134 let l:prevSameLevelLine = search( '\v^' . l:hashes . '[^#]', 'bnW' )
137 \ l:prevSameLevelLine > 0
140 \ l:prevLowerLevelLine == 0
142 \ l:prevLowerLevelLine < l:prevSameLevelLine
145 cal cursor( l:prevSameLevelLine, 0 )
147 ec 'no more siblings'
152 "mnemonics: ']' next (like a right arrow)
153 nn <buffer><silent> ]] :cal b:Markdown_GoNextHeader()<cr>
154 "vnoremap <buffer><silent> ]] /^#<cr><esc>:nohl<cr>gv
156 "mnemonics: '[' next (like a left arrow)
157 nn <buffer><silent> ][ :cal b:Markdown_GoNextSiblingHeader()<cr>
158 "vnoremap <buffer><silent> ][ <esc>:cal b:Markdown_GoNextHeaderSameLevel()<cr>
160 nn <buffer><silent> [] :cal b:Markdown_GoPreviousSiblingHeader()<cr>
162 nn <buffer><silent> [[ :cal b:Markdown_GoPreviousHeader()<cr>
163 "vnoremap <buffer><silent> [[ ?^#<cr><esc>:nohl<cr>gv
165 "go up one level. Menmonic: Up.
166 nn <buffer><silent> ]u :cal b:Markdown_GoHeaderUp()<cr>