Wikia

Vim Tips Wiki

Changes: Selecting changes in diff mode

Edit

Back to page

(Move categories to tip template)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 3: Line 3:
 
|previous=1055
 
|previous=1055
 
|next=1059
 
|next=1059
|created=November 24, 2005
+
|created=2005
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=Kartik Agaram
 
|author=Kartik Agaram
Line 13: Line 13:
 
This tip is for when you are working with a two-window vertical diff (comparing two files, side-by-side).
 
This tip is for when you are working with a two-window vertical diff (comparing two files, side-by-side).
   
Use <tt>]c</tt> and <tt>[c</tt> to go to a specific change. Then use M-, and M-. to patch using the version on the left or right respectively. The cursor is then positioned in the file that changed for ease of saving, etc.
+
Use <code>]c</code> and <code>[c</code> to go to a specific change. Then use M-, and M-. to patch using the version on the left or right respectively. The cursor is then positioned in the file that changed for ease of saving, etc.
   
 
I find this more intuitive than using diffput and diffget because I no longer need to remember which window the cursor is in.
 
I find this more intuitive than using diffput and diffget because I no longer need to remember which window the cursor is in.

Latest revision as of 06:06, July 13, 2012

Tip 1058 Printable Monobook Previous Next

created 2005 · complexity intermediate · author Kartik Agaram · version 6.0


This tip is for when you are working with a two-window vertical diff (comparing two files, side-by-side).

Use ]c and [c to go to a specific change. Then use M-, and M-. to patch using the version on the left or right respectively. The cursor is then positioned in the file that changed for ease of saving, etc.

I find this more intuitive than using diffput and diffget because I no longer need to remember which window the cursor is in.

The code:

function! DiffTake(dir, oppdir)
  let l:old = winnr()
  exec "wincmd ".a:dir
  " Assumption: just 2 windows side by side.
  if (winnr() == l:old)
    diffput
    exec "wincmd ".a:oppdir
  else
    wincmd p
    diffget
  endif
endfunction

function! SetupDiffMappings()
  if &diff
    map <Esc>, :call DiffTake("h", "l")<CR>
    map <Esc>. :call DiffTake("l", "h")<CR>
  endif
endfunction

" vim -d
call SetupDiffMappings()
" Entering diff mode from within vim - diffsplit, etc.
autocmd FilterWritePost * call SetupDiffMappings()

CommentsEdit

You might also like these settings (but it will require a little savy on keeping which side is which):

" <F11> moves to "previous" change location,
" <F12> moves to "next" change location,
map <F11> [c
map <F12> ]c

" SHIFT<F12> does a "diff put" change location,
map <S-F12> dp

Around Wikia's network

Random Wiki