]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge branch 'mapping'
authorHiroshi Shirosaki <h.shirosaki@gmail.com>
Thu, 3 Apr 2014 04:30:06 +0000 (13:30 +0900)
committerHiroshi Shirosaki <h.shirosaki@gmail.com>
Thu, 3 Apr 2014 04:30:06 +0000 (13:30 +0900)
Conflicts:
ftplugin/mkd.vim

1  2 
README.md
ftplugin/mkd.vim

diff --combined README.md
index 843405f0035e32819a0656151ae0746e58406191,cc1f7ef96ad2b16fe77cd453b96a55fd53408771..b004bbc539744d9efb0f3ecb514fbed6666d1dac
+++ 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 `<Plug>` 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. `<Plug>(Markdown_MoveToNextHeader)`
+ - `[[`: go to previous header. Contrast with `]c`. `<Plug>(Markdown_MoveToPreviousHeader)`
+ - `][`: go to next sibling header if any. `<Plug>(Markdown_MoveToNextSiblingHeader)`
+ - `[]`: go to previous sibling header if any. `<Plug>(Markdown_MoveToPreviousSiblingHeader)`
+ - `]c`: go to Current header. `<Plug>(Markdown_MoveToCurHeader)`
+ - `]u`: go to parent header (Up). `<Plug>(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 `<Enter>` 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 27fd855a61e6c5bf834937e1caf127a4a42ae3de,0627cc525f2f307ecf9bf31ab532ed85b98a526d..c7bac4e6dd716b9101ad2cd7b5301a8d424f9c1b
@@@ -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 <buffer><silent> ' . a:rhs . ' <esc>:call <sid>VisMove(''' . a:lhs . ''')<cr>'
  endfunction
  
- call <sid>MapNormVis(']]', 'b:Markdown_MoveToNextHeader')
- call <sid>MapNormVis('[[', 'b:Markdown_MoveToPreviousHeader')
- call <sid>MapNormVis('][', 'b:Markdown_MoveToNextSiblingHeader')
- call <sid>MapNormVis('[]', 'b:Markdown_MoveToPreviousSiblingHeader')
+ call <sid>MapNormVis('<Plug>(Markdown_MoveToNextHeader)', 'b:Markdown_MoveToNextHeader')
+ call <sid>MapNormVis('<Plug>(Markdown_MoveToPreviousHeader)', 'b:Markdown_MoveToPreviousHeader')
+ call <sid>MapNormVis('<Plug>(Markdown_MoveToNextSiblingHeader)', 'b:Markdown_MoveToNextSiblingHeader')
+ call <sid>MapNormVis('<Plug>(Markdown_MoveToPreviousSiblingHeader)', 'b:Markdown_MoveToPreviousSiblingHeader')
  " Menmonic: Up
- call <sid>MapNormVis(']u', 'b:Markdown_MoveToParentHeader')
+ call <sid>MapNormVis('<Plug>(Markdown_MoveToParentHeader)', 'b:Markdown_MoveToParentHeader')
  " Menmonic: Current
- call <sid>MapNormVis(']c', 'b:Markdown_MoveToCurHeader')
+ call <sid>MapNormVis('<Plug>(Markdown_MoveToCurHeader)', 'b:Markdown_MoveToCurHeader')
+ if ! exists('g:markdown_no_default_key_mappings')
+ \ || !g:markdown_no_default_key_mappings
+     nmap ]] <Plug>(Markdown_MoveToNextHeader)
+     nmap [[ <Plug>(Markdown_MoveToPreviousHeader)
+     nmap ][ <Plug>(Markdown_MoveToNextSiblingHeader)
+     nmap [] <Plug>(Markdown_MoveToPreviousSiblingHeader)
+     nmap ]u <Plug>(Markdown_MoveToParentHeader)
+     nmap ]c <Plug>(Markdown_MoveToCurHeader)
+     vmap ]] <Plug>(Markdown_MoveToNextHeader)
+     vmap [[ <Plug>(Markdown_MoveToPreviousHeader)
+     vmap ][ <Plug>(Markdown_MoveToNextSiblingHeader)
+     vmap [] <Plug>(Markdown_MoveToPreviousSiblingHeader)
+     vmap ]u <Plug>(Markdown_MoveToParentHeader)
+     vmap ]c <Plug>(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')