The condition “get the text between the first and second quotes” is easy to accomplish using the cut program:
$ echo "- 'autoindent' is set by default" | cut -d "'" -f 2 autoindent
longer way
in vim -e, you can transfer the current selected lines to an external program (for which we will use cut ) using the following construction:
:диапазон! внешняя-программа-или-команда
i.e., select the necessary lines in the visual mode by going to it by pressing V , then pressing ! and on the vim command line, get this text:
:'<,'>!
after it, enter the external command to make it like this:
:'<,'>! cut -d "'" -f 2
press enter and instead of all selected lines you get only words between the first and second quotes:
autoindent autoread backspace backupdir complete directory
press g v to repeat the selection of the same range of lines, then y to save them in the register (by default - in an unnamed register " ).
to return after this the original contents of the strings, press u .
if it is necessary to work not with a range of lines, but with all the lines of a file, then the whole procedure will be slightly shorter. execute the command:
:%! cut -d "'" -f 2
then copy all the resulting lines into a register (by default, unnamed):
:%y
then return the source strings by pressing u .
shorter way
- Copy the necessary lines into the nameless register (i.e., select them and press y ).
call the cut program using the system() function, passing it the contents of the unnamed register ( @" ), and write its output back to the same register:
:let @"=system("cut -d \"'\" -f 2",@")
quotes inside the parameters for the cut program had to be “locked”.
- now the nameless register contains the required strings. You can insert them in the right place, for example, by pressing p .
Of course, you can use any other register. storing strings in register a : " a y . addressing register a on the command line: @a (instead of @" ). paste from register a : " a p .