Permalink
Browse files

Initial stab at SCM conflict jumping

  • Loading branch information...
1 parent 440629a commit 8505f2eb3d7ff2bd0810f6e06cb103d783c05f5a @tpope committed Dec 7, 2011
Showing with 55 additions and 0 deletions.
  1. +8 −0 doc/unimpaired.txt
  2. +47 −0 plugin/unimpaired.vim
View
@@ -44,6 +44,14 @@ is "args" and for the "q" commands is "quickfix".
]o Go to the file succeeding the current one
alphabetically in the current file's directory.
+ *[n*
+]n Go to the previous SCM conflict marker. Try d[n
+ inside a conflict.
+
+ *]n*
+]n Go to the next SCM conflict marker. Try d]n inside a
+ conflict.
+
LINE OPERATIONS *unimpaired-lines*
*[<Space>*
View
@@ -75,6 +75,53 @@ nmap ]o <Plug>unimpairedONext
nmap [o <Plug>unimpairedOPrevious
" }}}1
+" Diff {{{1
+
+nmap [n <Plug>unimpairedContextPrevious
+nmap ]n <Plug>unimpairedContextNext
+omap [n <Plug>unimpairedContextPrevious
+omap ]n <Plug>unimpairedContextNext
+
+nnoremap <silent> <Plug>unimpairedContextPrevious :call <SID>Context(1)<CR>
+nnoremap <silent> <Plug>unimpairedContextNext :call <SID>Context(0)<CR>
+onoremap <silent> <Plug>unimpairedContextPrevious :call <SID>ContextMotion(1)<CR>
+onoremap <silent> <Plug>unimpairedContextNext :call <SID>ContextMotion(0)<CR>
+
+function! s:Context(reverse)
+ call search('^@@ .* @@\|^[<=>|]\{7}[<=>|]\@!', a:reverse ? 'bW' : 'W')
+endfunction
+
+function! s:ContextMotion(reverse)
+ if a:reverse
+ -
+ endif
+ call search('^@@ .* @@\|^diff \|^[<=>|]\{7}[<=>|]\@!', 'bWc')
+ if getline('.') =~# '^diff '
+ let end = search('^diff ', 'Wn') - 1
+ if end < 0
+ let end = line('$')
+ endif
+ elseif getline('.') =~# '^@@ '
+ let end = search('^@@ .* @@\|^diff ', 'Wn') - 1
+ if end < 0
+ let end = line('$')
+ endif
+ elseif getline('.') =~# '^=\{7\}'
+ +
+ let end = search('^>\{7}>\@!', 'Wnc')
+ elseif getline('.') =~# '^[<=>|]\{7\}'
+ let end = search('^[<=>|]\{7}[<=>|]\@!', 'Wn') - 1
+ else
+ return
+ endif
+ if end > line('.')
+ execute 'normal! V'.(end - line('.')).'j'
+ elseif end == line('.')
+ normal! V
+ endif
+endfunction
+
+" }}}1
" Line operations {{{1
function! s:BlankUp(count) abort

1 comment on commit 8505f2e

@richo
richo commented on 8505f2e Dec 7, 2011

Huzzah!

Please sign in to comment.