Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete the same line in multiple VI windows

Tags:

vim

vimdiff

I love using vim and vimdiff. I am currently working on comparing two files in vimdiff and I frequently run into the situation that I want to delete the same line in both buffers. In the following example I would like to delete lines 40 and 41.

39 text_a  |   39 text_b
40 text_aa |   40 text_aa
41 text_bb |   41 text_bb
42 text_c  |   42 text_d

It feels tedious to perform dd Ctrl-W-W, dd Ctrl-W-W to delete the line in the current window, jump to the other window, delete the line there and jump back to my original window.

Does anyone know a shortcut for this?

like image 342
yulivee Avatar asked Jul 18 '17 09:07

yulivee


People also ask

How do I delete a line that matches a pattern in vi?

The ex command g is very useful for acting on lines that match a pattern. You can use it with the d command, to delete all lines that contain a particular pattern, or all lines that do not contain a pattern.


1 Answers

You can use bufdo to delete lines 40 and 41 in all buffers

:bufdo 40,41d 

as per your case using vimdiff, the command is

:windo 40,41d 
like image 83
Lieven Keersmaekers Avatar answered Sep 19 '22 14:09

Lieven Keersmaekers