S
S
sonriente2014-05-10 10:48:30
vim
sonriente, 2014-05-10 10:48:30

How to parenthesize text in vim-e

Hello.
There is this text:

NAME_1  :  "Some name",
VALUE_1 : "Some value",
NAME_2  : "Some name2",
VALUE_2 : "Some value2"

How to turn it into the following using vim scripting:
1 : {
    NAME: "Some name",
    VALUE: "Some value"
},
2 : {
    NAME : "Some name2",
    VALUE: "Some value2"
}

Looked towards surround.vim. The plugin successfully wraps any selected block, but how to remove the indexes in the titles and add them before each block?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Marat Amerov, 2014-05-10
@amerov

:help q

S
SilentFl, 2014-07-08
@SilentFl

I would do it in the form of a macro that formats two lines. for example, for example, like this (cursor in the first column of the first line):
1) switch to the recording mode of the macro "a": qa
2) format with handles, for example like this: f_xdwO^C^Cpi: {^C^CjV>jV>f_xdwA< 80>kb^M},^C^Cj0
(^C^C is , or , <80> is a key (well, or replace it with ^C^CX), ^M - )
3) finish recording the macro: q
Now, if we have 100 lines that need to be converted into 50 records, we do [email protected] and rejoice

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question