How to remove text between all curly braces {} in vim

I want to remove all the text between each curly brace {} in the file (including the curly braces themselves). I know the% d command that deleted the text between curly braces under the cursor, but I want to do this automatically for the entire document.

Example: I have something like this:

public int getMinimum() {
    return min;
}
public void setMinimum(int min) {
    this.min= min;
}

I want to have something like this:

public int getMinimum()
public void setMinimum(int min)
+4
source share
3 answers

You can do this with the global command:

:g/{/normal f{da{

This means: for all lines containing {, go to the first * {in this line and delete everything from there to and enable the corresponding one }.

;, , , , , A; .

, , , {} s .


* {, {, {. . , f{F{, , - n- - , , .

+3

{ }, v%d.

+1

vim dot?

/{
d%

n. , . ? :

qqn.q
99@q

So the complete sequence will be: /{<cr>d%qqn.q99@q Why so? Because it is intuitive, and it is a completely vim way to do this, and you can adapt it to any situation.

0
source

Source: https://habr.com/ru/post/1653716/


All Articles