2012-07-12 35 views
3

這個問題是如何有選擇我們或他們有用的映射衝突塊像VIM:我們之間的選擇/他們的衝突塊

<<<<<<< HEAD 
ours code 
======= 
theirs code 
>>>>>>> branch 
+2

您需要將其分解爲正確的答案。參見[FAQ](http://stackoverflow.com/faq)。我會離開你一些時間自己做:) – sehe 2012-07-12 20:21:07

+0

你可以回答你自己的問題並接受它。 – 2012-07-12 20:22:09

+0

完成,謝謝你的建議:) – brauliobo 2012-07-12 20:51:29

回答

4

只是將下面的代碼粘貼到你的〜/ .vimrc和使用,fc,,so,st。 (在https://github.com/brauliobo/gitconfig完成的.vimrc)

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
" Find Nearest 
" Source: http://vim.1045645.n5.nabble.com/find-closest-occurrence-in-both-directions-td1183340.html 
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""               
function! FindNearest(pattern) 
    let @/=a:pattern 
    let b:prev = search(a:pattern, 'bncW') 
    if b:prev 
    let b:next = search(a:pattern, 'ncW') 
    if b:next 
     let b:cur = line('.') 
     if b:cur - b:prev == b:next - b:cur 
     " on a match 
     elseif b:cur - b:prev < b:next - b:cur 
     ? 
     else 
     /
     endif 
    else 
     ? 
    endif 
    else 
    /
    endif 
endfunction 

command! -nargs=1 FN call FindNearest(<q-args>) 
nmap \ :FN<space> 

""" Select between conflict blocks 
" select ours 
nmap <leader>so \<<<<<<<<CR>dd/=======<CR>V/>>>>>>><CR>d 
" select theirs 
nmap <leader>st \<<<<<<<<CR>V/=======<CR>dk/>>>>>>><CR>dd 
" find next conflict 
nmap <leader>fc /<<<<<<<<CR> 
3

我寫了一個插件是:ConflictMotions。它提供以下映射:

]x  Go to [count] next start of a conflict. 
    ]X  Go to [count] next end of a conflict. 
    [x  Go to [count] previous start of a conflict. 
    [X  Go to [count] previous end of a conflict. 
    ]z  Go to [count] next conflict marker. 
    [z  Go to [count] previous conflict marker. 

    ax  "a conflict" text object, select [count] conflicts, 
      including the conflict markers. 
    az  "a conflict section" text object, select [count] 
      sections (i.e. either ours, theirs, or base) including 
      the conflict marker above, and in the case of "theirs" 
      changes, also the ending conflict marker below. 
    iz  "inner conflict section" text object, select current 
      section (i.e. either ours, theirs, or base) without 
      the surrounding conflict markers. 
相關問題