From: Hiroshi Shirosaki Date: Thu, 3 Apr 2014 04:30:06 +0000 (+0900) Subject: Merge branch 'mapping' X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/893e8d81388f1c27368e963b61d34285d05f5a4b?ds=sidebyside;hp=-c Merge branch 'mapping' Conflicts: ftplugin/mkd.vim --- 893e8d81388f1c27368e963b61d34285d05f5a4b diff --combined README.md index 843405f,cc1f7ef..b004bbc --- a/README.md +++ b/README.md @@@ -48,29 -48,25 +48,37 @@@ Add the following line to your `.vimrc let g:vim_markdown_initial_foldlevel=1 ``` + **Disable Default Key Mappings** + + Add the following line to your `.vimrc` to disable default key mappings. You can map them by yourself with `` mappings + + ```vim + let g:markdown_no_default_key_mappings=1 + ``` + ## Mappings The following work on normal and visual modes: - - `]]`: go to next header. - - `[[`: go to previous header. Contrast with `]c`. - - `][`: go to next sibling header if any. - - `[]`: go to previous sibling header if any. - - `]c`: go to Current header. - - `]u`: go to parent header (Up). + - `]]`: go to next header. `(Markdown_MoveToNextHeader)` + - `[[`: go to previous header. Contrast with `]c`. `(Markdown_MoveToPreviousHeader)` + - `][`: go to next sibling header if any. `(Markdown_MoveToNextSiblingHeader)` + - `[]`: go to previous sibling header if any. `(Markdown_MoveToPreviousSiblingHeader)` + - `]c`: go to Current header. `(Markdown_MoveToCurHeader)` + - `]u`: go to parent header (Up). `(Markdown_MoveToParentHeader)` +## Commands + +The following commands currently only work for atx style headers (`#`). Pull request are welcome to extend them to Setext style headers (`===`). + +- `:Toc`: create a quickfix vertical window navigable table of contents with the headers. + + Hit `` on a line to jump to the corresponding line of the markdown file. + +- `:Toch`: Same as `:Toc` but in an horizontal window. +- `:Toct`: Same as `:Toc` but in a new tab. +- `:Tocv`: Same as `:Toc` for symmetry with `:Toch` and `Tocv`. + ## Credits The main contributors of vim-markdown are: diff --combined ftplugin/mkd.vim index 27fd855,0627cc5..c7bac4e --- a/ftplugin/mkd.vim +++ b/ftplugin/mkd.vim @@@ -294,39 -294,6 +294,39 @@@ function! b:Markdown_MoveToPreviousSibl endif endfunction +function! b:Markdown_Toc(...) + if a:0 > 0 + let l:window_type = a:1 + else + let l:window_type = 'vertical' + endif + silent vimgrep '^#' % + if l:window_type ==# 'horizontal' + copen + elseif l:window_type ==# 'vertical' + vertical copen + let &winwidth=(&columns/2) + elseif l:window_type ==# 'tab' + tab copen + else + copen + endif + set modifiable + %s/\v^([^|]*\|){2,2} #// + for i in range(1, line('$')) + let l:line = getline(i) + let l:header = matchstr(l:line, '^#*') + let l:length = len(l:header) + let l:line = substitute(l:line, '\v^#*[ ]*', '', '') + let l:line = substitute(l:line, '\v[ ]*#*$', '', '') + let l:line = repeat(' ', (2 * l:length)) . l:line + call setline(i, l:line) + endfor + set nomodified + set nomodifiable + normal! gg +endfunction + " Wrapper to do move commands in visual mode. " function! s:VisMove(f) @@@ -341,16 -308,29 +341,34 @@@ function! s:MapNormVis(rhs,lhs execute 'vn ' . a:rhs . ' :call VisMove(''' . a:lhs . ''')' endfunction - call MapNormVis(']]', 'b:Markdown_MoveToNextHeader') - call MapNormVis('[[', 'b:Markdown_MoveToPreviousHeader') - call MapNormVis('][', 'b:Markdown_MoveToNextSiblingHeader') - call MapNormVis('[]', 'b:Markdown_MoveToPreviousSiblingHeader') + + call MapNormVis('(Markdown_MoveToNextHeader)', 'b:Markdown_MoveToNextHeader') + call MapNormVis('(Markdown_MoveToPreviousHeader)', 'b:Markdown_MoveToPreviousHeader') + call MapNormVis('(Markdown_MoveToNextSiblingHeader)', 'b:Markdown_MoveToNextSiblingHeader') + call MapNormVis('(Markdown_MoveToPreviousSiblingHeader)', 'b:Markdown_MoveToPreviousSiblingHeader') " Menmonic: Up - call MapNormVis(']u', 'b:Markdown_MoveToParentHeader') + call MapNormVis('(Markdown_MoveToParentHeader)', 'b:Markdown_MoveToParentHeader') " Menmonic: Current - call MapNormVis(']c', 'b:Markdown_MoveToCurHeader') + call MapNormVis('(Markdown_MoveToCurHeader)', 'b:Markdown_MoveToCurHeader') + + if ! exists('g:markdown_no_default_key_mappings') + \ || !g:markdown_no_default_key_mappings + nmap ]] (Markdown_MoveToNextHeader) + nmap [[ (Markdown_MoveToPreviousHeader) + nmap ][ (Markdown_MoveToNextSiblingHeader) + nmap [] (Markdown_MoveToPreviousSiblingHeader) + nmap ]u (Markdown_MoveToParentHeader) + nmap ]c (Markdown_MoveToCurHeader) + + vmap ]] (Markdown_MoveToNextHeader) + vmap [[ (Markdown_MoveToPreviousHeader) + vmap ][ (Markdown_MoveToNextSiblingHeader) + vmap [] (Markdown_MoveToPreviousSiblingHeader) + vmap ]u (Markdown_MoveToParentHeader) + vmap ]c (Markdown_MoveToCurHeader) + endif + +command! -buffer Toc call b:Markdown_Toc() +command! -buffer Toch call b:Markdown_Toc('horizontal') +command! -buffer Tocv call b:Markdown_Toc('vertical') +command! -buffer Toct call b:Markdown_Toc('tab')