Help with regular command creation for editor vi

Hi, I need help.

I need to build command for line command editor vi. I want to take the whole string and assemble it in a regular expression. He then folded into another shape.

Can anyone help me?

You gave us no details. Makes it hard to help you.

An overview of what you want:
.exrc is a setup file for vi, where you define keystrokes to be macros.
Create the macros you need in the .exrc file in your home directory.

Here are examples of how to do that:
my .exrc

Now you need to tell us what exactly you mean by 'regular expression from string'

1 Like

I am sorry.

I need to take one line and divide it by a chain. Then I want to make that string in a different order.

Example I have:
dog-cat-mouse-horse-duck

And I need it:
mouse-cat-dog-duk-horse
[2, 1, 0, 4, 3]

echo "dog-cat-mouse-horse-duck" | awk -F- '{$0=$3 OFS $2 OFS $1 OFS $5 OFS $4} 1' OFS=-

To rearrange the first five fields of all lines in a file named file that contain five or more <hyphen> separated fields and leave other lines unchanged, you could use:

sed 's/\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)/\3-\2-\1-\5-\4/' file

Note that BRE back references count fields starting at 1, not 0.

If you are in vi with file currently loaded into the editing buffer and want to make that change to all lines in the buffer that match that pattern, the command to type into vi would be:

:g/\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)/s//\3-\2-\1-\5-\4/

If this isn't what you want, you need to write a much clearer statement of your requirements, tell us what operating system you're using, what shell you're using, where these strings are located, where you want the results to be placed, etc.

Note, however, that the above code will NOT change "duck" to "duk" while it rearranges the fields. If you really want to do that, you'll need to further explain the logic used to determine which letters to drop from which fields while rearranging fields.