vim Script: Switching between modes

Hi All,

I've been using vi for about 10 years, but this is my first attempt at creating a vi script. I am reformatting some files to create CSVs for import into a database. In the script, I have a bunch of substitute lines that work fine, but I'm trying to figure out how to get the script into insert mode and then back to command mode so I can run commands such as:

d1G
dG
1G

I've tried typing <ESC> into the script, but vi doesn't seem to recognize it. What can I use to switch modes?

Thanks,

Dkr.

Did you try pressing <CTRL>+<V> key before pressing the <ESC> key ?

---------- Post updated at 11:35 PM ---------- Previous update was at 11:23 PM ----------

You can use macro in vi

macro in command mode
:map <key> <command>

in text mode
:map! <key> <command>

use tab to expand a macro.

So you can try to define macro that work in text mode then expand it ?

If you put an example of how your input file look like and the output you expect maybe we can help you to format it another way (sed/awk like).

---------- Post updated at 11:36 PM ---------- Previous update was at 11:35 PM ----------

to load the file containing macro
:so <filename>

---------- Post updated at 11:38 PM ---------- Previous update was at 11:36 PM ----------

...but it is a VERY VERY VERY long time since i used it so ... not sure the vi version i used behave the same way than your current one.

---------- Post updated at 11:49 PM ---------- Previous update was at 11:38 PM ----------

if you are just trying to remove first and last line of a file :

sed -i "" '1d;$d' yourfile

What I have is an HTML product catalog that has written text like product descriptions and the like and below it there is product specifications which is what I am grabbing for my database. Basically, I'm just looking to delete the first n lines of the file. However, n is dependent on wherever the written text ends. I can do it easily with vi commands in insert mode, but not command mode. I may just end up writing a macro and calling it from my script for the parts I can't do in command mode.

Dkr.

"However, n is dependent on wherever the written text ends"

Please post an example of input and expected output so we may be able to help you to generate the output as you need