Add new lines using vertical VIM selection

Assume the following file contents are opened in VIM:

function a1 {}
function a2 {}
function a3 {}
function a4 {}
function a5 {}
function a6 {}
function a7 {}

I want to expand all the functions in this style:

function an {

}

For this, I tried using vertical selection (using Ctrl+ V):

function a1 {█
function a2 {█
function a3 {█
function a4 {█
function a5 {█
function a6 {█
function a7 {█

Then I clicked I. Then Enter(in insert mode):

function a1 {
}
function a2 {}
function a3 {}
function a4 {}
function a5 {}
function a6 {}
function a7 {}

Then I clicked Esc. I expected to expand all the blocks. Nothing happened. Why?

I know that a simple replacement or macro will save me. I know there are alternatives, but I want to know why a new row was not added when using vertical selection.

+4
source share
4 answers

Ctrl + V " ", " ". , "" () .

, , . Vim , , "".

+6

, :substitution , . :

:'<,'>s/{}$/{\r\r}/

, , , ( ).

0

, vim, :

(v_b_c): . "c" Insert. ( ). , .

, , :

  • , , 1x3:

    ctrl Vjjj

  • - , , , " NEWL":

    shift INEWL esc

  • , :

    shift Vjjj

  • (ctrl v enter → ^ M), :

    : /NewL/ ctrl v enter/

0
source

try using sed:

:%!sed 's/}/\n\n}/g

read at the bottom of your answer and realized that you weren’t looking for a workaround ... I'm not sure why it doesn’t work.

-1
source

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


All Articles