Skip to main content
added 169 characters in body
Source Link
statox
  • 50.5k
  • 19
  • 153
  • 231

I didn't test it but you need to use :h :norm:

:norm[al][!] {commands}                 *:norm* *:normal*
            Execute Normal mode commands {commands}.  This makes
            it possible to execute Normal mode commands typed on
            the command-line.  {commands} are executed like they
            are typed.  For undo all commands are undone together.
            Execution stops when an error is encountered.

Which would give you the following file:

%s/string/string$i/g
norm! V
norm! 19j
norm! y
vs output.file
norm! G
norm! p
wqa

Also note that you don't need to put : in front of your normal mode command when they are written in a script.

Also, for what it's worth I would not use Vim for what you are trying to do. I think grep with the -A parameter would be enough to get only the 19 lines after your matched string. And you can pipe it to sed to do you substitution. 

Probably something along the lines of

grep -A 19 "string" file-to-edit | sed 's/string/string$i/' > output.file

If you have many files this should me faster because grep and sed are specialized for these tasks and should be better than Vim. Also since you are now in the terminal you can use the * joker to treat all of your files.

I didn't test it but you need to use :h :norm:

:norm[al][!] {commands}                 *:norm* *:normal*
            Execute Normal mode commands {commands}.  This makes
            it possible to execute Normal mode commands typed on
            the command-line.  {commands} are executed like they
            are typed.  For undo all commands are undone together.
            Execution stops when an error is encountered.

Which would give you the following file:

%s/string/string$i/g
norm! V
norm! 19j
norm! y
vs output.file
norm! G
norm! p
wqa

Also note that you don't need to put : in front of your normal mode command when they are written in a script.

Also, for what it's worth I would not use Vim for what you are trying to do. I think grep with the -A parameter would be enough. Probably something along the lines of

grep -A 19 "string" file-to-edit > output.file

I didn't test it but you need to use :h :norm:

:norm[al][!] {commands}                 *:norm* *:normal*
            Execute Normal mode commands {commands}.  This makes
            it possible to execute Normal mode commands typed on
            the command-line.  {commands} are executed like they
            are typed.  For undo all commands are undone together.
            Execution stops when an error is encountered.

Which would give you the following file:

%s/string/string$i/g
norm! V
norm! 19j
norm! y
vs output.file
norm! G
norm! p
wqa

Also note that you don't need to put : in front of your normal mode command when they are written in a script.

Also, for what it's worth I would not use Vim for what you are trying to do. I think grep with the -A parameter would be enough to get only the 19 lines after your matched string. And you can pipe it to sed to do you substitution. 

Probably something along the lines of

grep -A 19 "string" file-to-edit | sed 's/string/string$i/' > output.file

If you have many files this should me faster because grep and sed are specialized for these tasks and should be better than Vim. Also since you are now in the terminal you can use the * joker to treat all of your files.

Source Link
statox
  • 50.5k
  • 19
  • 153
  • 231

I didn't test it but you need to use :h :norm:

:norm[al][!] {commands}                 *:norm* *:normal*
            Execute Normal mode commands {commands}.  This makes
            it possible to execute Normal mode commands typed on
            the command-line.  {commands} are executed like they
            are typed.  For undo all commands are undone together.
            Execution stops when an error is encountered.

Which would give you the following file:

%s/string/string$i/g
norm! V
norm! 19j
norm! y
vs output.file
norm! G
norm! p
wqa

Also note that you don't need to put : in front of your normal mode command when they are written in a script.

Also, for what it's worth I would not use Vim for what you are trying to do. I think grep with the -A parameter would be enough. Probably something along the lines of

grep -A 19 "string" file-to-edit > output.file