reaching out from vi

By Paul Murphy, author of The Unix Guide to Defenestration

When you are editing a file with vi, you can often use its ability to co-operate with the shell to your advantage.

If you are working in a GUI environment, say on a Sun console or an NCD X-terminal with a Sun style keyboard; just highlight the source you want copied, hit the "Copy" key; go into insert (or add) mode in the target file and press the "Paste" key.

That's easy, but what if you're not working in a GUI? Many people are forced to work in the Windows time machine - aka telnet. No cut and paste there, so what do you do?

Do what we did in 1983, the year before Sunview. For example, while editing one file in vi, you can read in another file using ":r file_name" and then delete what you don't want - but there are several better ways.

!!head -200 file_name |tail 50

will replace your current line with line 151 through 200 of the target file.


!! sed -n '/reference_pattern/p' filename

will replace the current line with all lines matching the pattern in the source file.


!! cat `which my_script`

will find and read-in "my_script" (provided its in your path).