VIM command for editing patches

Is there a VIM command that can delete the current line and all following lines until it meets a line starting with "---" (or "diff" depending on the type of diff file)? I'm still working on merging patches and looking for ways to make it less painful. -- My Main Blog http://etbe.coker.com.au/ My Documents Blog http://doc.coker.com.au/

On Mon, 11 Jun 2012 16:21:31 +1000, Russell Coker <russell@coker.com.au> wrote:
Is there a VIM command that can delete the current line and all following lines until it meets a line starting with "---" (or "diff" depending on the type of diff file)?
You can delete to a regular expression, eg: d/^---- You can also map this whole thing to a key (eg a function key), so you can repeat it easily: :map <f2> d/^----<cr> regards, Glenn -- sks-keyservers.net 0xb1e82ec9228ac090

On 11 June 2012 16:45, Glenn McIntosh <neonsignal@memepress.org> wrote:
You can delete to a regular expression, eg:
d/^----
I don't like doing this, you lose the current search string. I would look for or create plugin for vim to do this, for some background see: http://blog.carbonfive.com/2011/10/17/vim-text-objects-the-definitive-guide/ -- Brian May <brian@microcomaustralia.com.au>

Brian May <brian@microcomaustralia.com.au> wrote:
On 11 June 2012 16:45, Glenn McIntosh <neonsignal@memepress.org> wrote:
You can delete to a regular expression, eg:
d/^----
I don't like doing this, you lose the current search string.
What happens if you use: :.,/^------/d Note that it will delete the current line but you can easily adjust if that isn't what you want.

On 12 June 2012 16:56, Jason White <jason@jasonjgw.net> wrote:
What happens if you use: :.,/^------/d Note that it will delete the current line but you can easily adjust if that isn't what you want.
A quick test seems to indicate this will overwrite the current search string too :-( -- Brian May <brian@microcomaustralia.com.au>

On Tue, 12 Jun 2012 09:40:14 +1000, Brian May <brian@microcomaustralia.com.au> wrote:
d/^----
I don't like doing this, you lose the current search string.
Yeah, I agree, I find that annoying. Though you can scroll back through your previous search history (up/down arrow after typing '/'); this history is even retained between invocations of vim. Glenn -- sks-keyservers.net 0xb1e82ec9228ac090

On 11.06.12 16:21, Russell Coker wrote:
Is there a VIM command that can delete the current line and all following lines until it meets a line starting with "---" (or "diff" depending on the type of diff file)?
I'm still working on merging patches and looking for ways to make it less painful.
OK, you're not blindly applying the patches, but manually selecting a subset of the changes to apply. There are two methods I've used for that, over the years: a) Blindly apply the patches to a copy of the files, then either use $ sdiff -o result patched.file unpatched.file Answer l or r <CR> to choose whether to apply each region of the patch. (In full context, it is easier than trying to decide based only on the patch, usually.) OR, instead of sdiff, using vim: ( :h vimdiff ) $ vimdiff -o file1 file2 # -o => Horizontal split, good for long # lines. Commands to get started: ]c Move to next diff. [c Move to previous diff. You're in vim, and can make changes to synchronise the files, or make other tweaks while you're there. :h diffput :h diffget :h diffupdate To save on keystrokes, I have the following in .vimrc: " For vimdiff: noremap <F9> :diffget<CR>]c " Copy 1st <- 2nd file & go to next change. noremap <F10> :diffput<CR>]c " Copy 1st -> 2nd file & go to next change. b) OTOH, if it's only merge conflicts which merit immediate attention, blindly apply the patches to a copy of the files, which are checked out from CVS. Do the merge of several thousand files with a cvs update, cvs commit sequence. (OK, git then, nowadays. :) The attached script, which I used to speed up resolution of the merge conflicts, might be adaptable to your use case. Even if it's not just merge conflicts you're targeting, then changing the /^<</ , /^>>/ delimiters, and the /^==/ separator, to suit unified diff (or whatever you have), could come close to handling the task? It works in a tmp directory, and prompts before overwriting the input file. Hopefully some variant of what has helped me perform multi-thousand file code merges, with innumerable changes, in an afternoon will be of some use. Erik -- Duct tape is like the force. It has a light side, and a dark side, and it holds the universe together. - Carl Zwanzig

On 11.06.12 18:37, Erik Christiansen wrote:
nawk '
s/nawk/awk Nawk was all I had to hand, back then. There's only standard awk in the simple script. (Though I don't hesitate to use gawk extensions, where useful.) Erik -- If you stew apples like cranberries, they taste more like prunes than rhubarb does. - Groucho Marx
participants (5)
-
Brian May
-
Erik Christiansen
-
Glenn McIntosh
-
Jason White
-
Russell Coker