A Conversation for VI Text Editor

explanation of macros?

Post 1

yitz

i haven't found any documentation that explains how to add macros to VI .. at least not in the man pages. an explanation would be appreciated. (or better yet, a pointer to an existing explanation smiley - smiley)


explanation of macros?

Post 2

Fistandantilus

hi yitz,
i think when he said macros he ment the use of VI to build scripts in c,shell,perl or others.
you can use vi to call and excute other files(edited by vi or someting else),sql phrases(SQL - the lenguage of DATA BASES,like oracle or access),etc'.
for doing so you must know to program in : c,shell,perl or other.
the most simple one is using the shell you are in to program(sh,csh,tcsh,ksh,bsh and so on), and changing the file to excute mode by typing the command :
chmod +x < NAME OF THE FILE + EXTENTION>
so you don't have to use compiler(something you must in any other programing lenguge).
i hope i'v helped you.


explanation of macros

Post 3

Fistandantilus

hi yitz,
i think when he said macros he ment the use of VI to build scripts in c,shell,perl or others.
you can use vi to call and excute other files(edited by vi or someting else),sql phrases(SQL - the lenguage of DATA BASES,like oracle or access),etc'.
for doing so you must know to program in : c,shell,perl or other.
the most simple one is using the shell you are in to program(sh,csh,tcsh,ksh,bsh and so on), and changing the file to excute mode by typing the command :
chmod +x
so you don't have to use compiler(something you must in any other programing lenguge).
i hope i'v helped you.


explanation of macros?

Post 4

yitz

unless i misunderstood you, i don't think he meant just using vi to create shell-scripts..

it seems there MUST be some way to use user-defined MACROs from within vi, i've just never figured out how (and there doesn't seem to be anything in the man, which would suggest there is no way to do so.) I find it hard to believe that such a popular text editor would remain with no easy way to script simple repetetive macros.. someone must know how to do so, or i will have to re-learn emacs smiley - sadface


explanation of macros?

Post 5

Dave the Elbow

If by your definition of "macros" you mean to be able to enter specific formats or template lines for example, then this is not possible unless you are copying from within the same file using the keyboad shortcuts.

"Vi" is not, and was never intended to be a full blown word processor or development system. It is purely and simply an ascii file editor, with added tools for programmers (i.e. bracket matching, auto indent etc..).

I have used Vi on UNIX and Xenix systems, primarily for the modification of user .profiles and ascii system files (e.g. files in /etc/rc.d/ or termcap entries), but also for developing in 'C'.

It is not my intention to dissuade you from using Vi, merely to alert you to the main reasons why you should use it


explanation of macros?

Post 6

Uncle Ghengis

Of course you can use macros within vi...

(Sometimes the man pages are split between "man vi" and "man ex")

Incidentally, you can get your own local man pages (for annotating) by
running a command like:

$ man vi | col -b > manvi

Anyway. You can easily add extra key functions by adding to the .exrc file (normally held in your home directory, and don't forget that dot!)
I have quite a few extra key assignments for vi, (so I have to take my .exrc file with me wherever I go!)

For example, I use Ctrl-T as a "swap the next two whitespace delimited words" command. (map ^T WdWBP in your .exrc)

Similarly, it's even possible to use vi as a stream editor! You can
create a file like:

O#Header Comment[ESC]
:4IFoo[Esc]
:5,$ s/^/ Bar/
Go#Trailer[ESC]

And then just pipe files to edit at it:

for i in *
do
vi $i < vi_script
done

Which basically takes each file in the current directory
Adds a header coment,
Adds "Foo" to the beginning of the 4th line,
Inserts " Bar" to the beginning of all lines 5th to the end.
Appends a line saying "Trailer" at the end.

Did I mention that I *love* vi!


Key: Complain about this post

Write an Entry

"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."

Write an entry
Read more