making each line double vim making each line double vim shell shell

making each line double vim


Try this:

:%s/.*/echo "\0"\rcat \0/g

Explanation:

:%s/a/b/g means search whole file and replace a to b.

.* means match every thing in one line.

\0 means the matched thing.

\r means the new line.


alternatively you could apply a macro

yypha"<esc>^iecho "<esc>j^icat <esc>j
  • yypha" yanks the current line puts it below the current and go up with h
  • a"<esc> appends a " and goes back to normal mode
  • ^iecho "<esc> puts echo " in front of the file* and again goes to normal
  • j^icat<esc> prepends cat on the next line and
  • j at last goes to the next line to be ready for reapplying the macro

you can either record the macro by pressing qq and the buttons as described or

write yypha"^[^iecho "^[j^icat ^[j with ^[ being entered as Ctrl-V then Esc and then "qyy to yank the line in the q-th register, which is then also an executable macro.

The macro itself you can run with @q once or 30@q thirty times.


I'd usually go with the accepted answer, but just to show that command-mode (Ex) commands can be nice too:

:g/^./t. | norm! icat␣^Ok^O0echo␣"^OA"

Note: enter the keycodes using ^V (e.g. ^V^O). On windows, ^Q has that function by default)

Explanation

  • :g/^./ (repeat for every line containing at least one char)
  • t. (duplicate the line below)
  • the rest:

    • insert `'cat ``,
    • ^Ok (up a line)
    • ^O0 (at start of line)
    • insert 'echo "'
    • append '"' at end of line