Skip to content
This repository
Browse code

Initial stab at SCM conflict jumping

  • Loading branch information...
commit 8505f2eb3d7ff2bd0810f6e06cb103d783c05f5a 1 parent 440629a
Tim Pope authored December 07, 2011
8  doc/unimpaired.txt
@@ -44,6 +44,14 @@ is "args" and for the "q" commands is "quickfix".
44 44
 ]o                      Go to the file succeeding the current one
45 45
                         alphabetically in the current file's directory.
46 46
 
  47
+                                                *[n*
  48
+]n                      Go to the previous SCM conflict marker.  Try d[n
  49
+                        inside a conflict.
  50
+
  51
+                                                *]n*
  52
+]n                      Go to the next SCM conflict marker.  Try d]n inside a
  53
+                        conflict.
  54
+
47 55
 LINE OPERATIONS                                 *unimpaired-lines*
48 56
 
49 57
                                                 *[<Space>*
47  plugin/unimpaired.vim
@@ -75,6 +75,53 @@ nmap ]o <Plug>unimpairedONext
75 75
 nmap [o <Plug>unimpairedOPrevious
76 76
 
77 77
 " }}}1
  78
+" Diff {{{1
  79
+
  80
+nmap [n <Plug>unimpairedContextPrevious
  81
+nmap ]n <Plug>unimpairedContextNext
  82
+omap [n <Plug>unimpairedContextPrevious
  83
+omap ]n <Plug>unimpairedContextNext
  84
+
  85
+nnoremap <silent> <Plug>unimpairedContextPrevious :call <SID>Context(1)<CR>
  86
+nnoremap <silent> <Plug>unimpairedContextNext     :call <SID>Context(0)<CR>
  87
+onoremap <silent> <Plug>unimpairedContextPrevious :call <SID>ContextMotion(1)<CR>
  88
+onoremap <silent> <Plug>unimpairedContextNext     :call <SID>ContextMotion(0)<CR>
  89
+
  90
+function! s:Context(reverse)
  91
+  call search('^@@ .* @@\|^[<=>|]\{7}[<=>|]\@!', a:reverse ? 'bW' : 'W')
  92
+endfunction
  93
+
  94
+function! s:ContextMotion(reverse)
  95
+  if a:reverse
  96
+    -
  97
+  endif
  98
+  call search('^@@ .* @@\|^diff \|^[<=>|]\{7}[<=>|]\@!', 'bWc')
  99
+  if getline('.') =~# '^diff '
  100
+    let end = search('^diff ', 'Wn') - 1
  101
+    if end < 0
  102
+      let end = line('$')
  103
+    endif
  104
+  elseif getline('.') =~# '^@@ '
  105
+    let end = search('^@@ .* @@\|^diff ', 'Wn') - 1
  106
+    if end < 0
  107
+      let end = line('$')
  108
+    endif
  109
+  elseif getline('.') =~# '^=\{7\}'
  110
+    +
  111
+    let end = search('^>\{7}>\@!', 'Wnc')
  112
+  elseif getline('.') =~# '^[<=>|]\{7\}'
  113
+    let end = search('^[<=>|]\{7}[<=>|]\@!', 'Wn') - 1
  114
+  else
  115
+    return
  116
+  endif
  117
+  if end > line('.')
  118
+    execute 'normal! V'.(end - line('.')).'j'
  119
+  elseif end == line('.')
  120
+    normal! V
  121
+  endif
  122
+endfunction
  123
+
  124
+" }}}1
78 125
 " Line operations {{{1
79 126
 
80 127
 function! s:BlankUp(count) abort

1 note on commit 8505f2e

Richo Healey

Huzzah!

Please sign in to comment.
Something went wrong with that request. Please try again.