From: Jon LaBadie on 18 Apr 2010 23:02 steve wrote: > How, in 'vi', do I make an interactive macro? > > I'm going along in insert mode and at some point I want to pull up a > form and fill it in, say, > > Name: <enter something> > Rank: <enter something> > Serial Number: <enter something> > > and back to the normal insert mode. I've tried simply having the form > as a separate script and invocing it with '!' but it will not pause > for input. Try "reading" from the separate script. I.e. the macro will do a :r !<script> In the script do things like: printf "Enter your name: " > /dev/tty read name printf "Enter your rank: " > /dev/tty read rank ... printf "%s\n%s\n%s\n" "$name" "$rank" "$serialnum" The redirect of the prompts keeps them from being read as input by vi.
From: Jon LaBadie on 20 Apr 2010 10:34 steve wrote: On Apr 18, 10:02 pm, Jon LaBadie <jlaba...(a)aXcXm.org> wrote: >> What problems do you encounter if you eliminate the tmp file >> as in the following (based on my orig suggestion). >> >> #!/bin/sh >> >> clear # may need 'tput clear > /dev/tty' >> printf "Enter data1: " > /dev/tty >> read data1 >> printf "Enter data2: " > /dev/tty >> read data2 >> printf "Enter data3: " > /dev/tty >> read data3 >> >> printf " Data1: %s\n" $data1 >> printf " Data2: %s\n" $data2 >> printf " Data3: %s\n" $data3 >> >> # end script file >> >> :map! ;jj ^[:r !script^M > > computer just hangs. I'm running bash 3.1.17(2) and my vi is elvis > 2.2.0. This is on a slackware64-13.0 box. > Well, try naming your shell script something other than the name of a command in /usr/bin :)) Or give a full path name to your "script". Also, I'm certain you will need "tput clear > /dev/tty" Also, quote your variables in the last 3 printf lines.
From: steve on 19 Apr 2010 12:09 On Apr 18, 10:02 pm, Jon LaBadie <jlaba...(a)aXcXm.org> wrote: > steve wrote: > > How, in 'vi', do I make an interactive macro? > > > I'm going along in insert mode and at some point I want to pull up a > > form and fill it in, say, > > > Name: <enter something> > > Rank: <enter something> > > Serial Number: <enter something> > > > and back to the normal insert mode. I've tried simply having the form > > as a separate script and invocing it with '!' but it will not pause > > for input. > > Try "reading" from the separate script. I.e. the macro will do a :r !<script> > > In the script do things like: > > printf "Enter your name: " > /dev/tty > read name > printf "Enter your rank: " > /dev/tty > read rank > ... > > printf "%s\n%s\n%s\n" "$name" "$rank" "$serialnum" > > The redirect of the prompts keeps them from being read as input by vi. Jon, thank you for your reply. It was very helpful in putting me on (I hope) the right track. For anybody interested my solution so far is to have a script file: #!/bin/sh clear printf "Enter data1: " read data1 printf "Enter data2: " read data2 printf "Enter data3: " read data3 printf " Data1: %s\n" $data1 > btmp.txt printf " Data2: %s\n" $data2 >> btmp.txt printf " Data3: %s\n" $data3 >> btmp.txt # end script file and then my vi macro is :map! ;jj ^[!script^M:r btmp.txt^M It's not the exact solution I wanted but it may be as close as I'll get. --
From: Jon LaBadie on 19 Apr 2010 15:06 steve wrote: > On Apr 18, 10:02 pm, Jon LaBadie <jlaba...(a)aXcXm.org> wrote: >> steve wrote: >>> How, in 'vi', do I make an interactive macro? >>> I'm going along in insert mode and at some point I want to pull up a >>> form and fill it in, say, >>> Name: <enter something> >>> Rank: <enter something> >>> Serial Number: <enter something> >>> and back to the normal insert mode. I've tried simply having the form >>> as a separate script and invocing it with '!' but it will not pause >>> for input. >> Try "reading" from the separate script. I.e. the macro will do a :r !<script> >> >> In the script do things like: >> >> printf "Enter your name: " > /dev/tty >> read name >> printf "Enter your rank: " > /dev/tty >> read rank >> ... >> >> printf "%s\n%s\n%s\n" "$name" "$rank" "$serialnum" >> >> The redirect of the prompts keeps them from being read as input by vi. > > > Jon, thank you for your reply. It was very helpful in putting me on > (I hope) the > right track. > > For anybody interested my solution so far is to have a script file: > > #!/bin/sh > > clear > printf "Enter data1: " > read data1 > printf "Enter data2: " > read data2 > printf "Enter data3: " > read data3 > > printf " Data1: %s\n" $data1 > btmp.txt > printf " Data2: %s\n" $data2 >> btmp.txt > printf " Data3: %s\n" $data3 >> btmp.txt > > # end script file > > and then my vi macro is > > :map! ;jj ^[!script^M:r btmp.txt^M > > It's not the exact solution I wanted but it may be as close as I'll > get. > What problems do you encounter if you eliminate the tmp file as in the following (based on my orig suggestion). #!/bin/sh clear # may need 'tput clear > /dev/tty' printf "Enter data1: " > /dev/tty read data1 printf "Enter data2: " > /dev/tty read data2 printf "Enter data3: " > /dev/tty read data3 printf " Data1: %s\n" $data1 printf " Data2: %s\n" $data2 printf " Data3: %s\n" $data3 # end script file :map! ;jj ^[:r !script^M
From: steve on 19 Apr 2010 17:52 On Apr 19, 2:06 pm, Jon LaBadie <jlaba...(a)aXcXm.org> wrote: > steve wrote: > > On Apr 18, 10:02 pm, Jon LaBadie <jlaba...(a)aXcXm.org> wrote: > >> steve wrote: > >>> How, in 'vi', do I make an interactive macro? > >>> I'm going along in insert mode and at some point I want to pull up a > >>> form and fill it in, say, > >>> Name: <enter something> > >>> Rank: <enter something> > >>> Serial Number: <enter something> > >>> and back to the normal insert mode. I've tried simply having the form > >>> as a separate script and invocing it with '!' but it will not pause > >>> for input. > >> Try "reading" from the separate script. I.e. the macro will do a :r !<script> > > >> In the script do things like: > > >> printf "Enter your name: " > /dev/tty > >> read name > >> printf "Enter your rank: " > /dev/tty > >> read rank > >> ... > > >> printf "%s\n%s\n%s\n" "$name" "$rank" "$serialnum" > > >> The redirect of the prompts keeps them from being read as input by vi. > > > Jon, thank you for your reply. It was very helpful in putting me on > > (I hope) the > > right track. > > > For anybody interested my solution so far is to have a script file: > > > #!/bin/sh > > > clear > > printf "Enter data1: " > > read data1 > > printf "Enter data2: " > > read data2 > > printf "Enter data3: " > > read data3 > > > printf " Data1: %s\n" $data1 > btmp.txt > > printf " Data2: %s\n" $data2 >> btmp.txt > > printf " Data3: %s\n" $data3 >> btmp.txt > > > # end script file > > > and then my vi macro is > > > :map! ;jj ^[!script^M:r btmp.txt^M > > > It's not the exact solution I wanted but it may be as close as I'll > > get. > > What problems do you encounter if you eliminate the tmp file > as in the following (based on my orig suggestion). > > #!/bin/sh > > clear # may need 'tput clear > /dev/tty' > printf "Enter data1: " > /dev/tty > read data1 > printf "Enter data2: " > /dev/tty > read data2 > printf "Enter data3: " > /dev/tty > read data3 > > printf " Data1: %s\n" $data1 > printf " Data2: %s\n" $data2 > printf " Data3: %s\n" $data3 > > # end script file > > :map! ;jj ^[:r !script^M computer just hangs. I'm running bash 3.1.17(2) and my vi is elvis 2.2.0. This is on a slackware64-13.0 box. --
First
|
Prev
|
Pages: 1 2 Prev: sed delete match line not work Next: XTerm question: How to get current window title? |