thanks, tony and gary. it was of great help. can you please point to some online resource where one can learn writing these kinds of basic and small useful VIM scripts? -k
----- Original Message ---- From: Gary Johnson <[EMAIL PROTECTED]> To: [email protected] Sent: Wednesday, August 23, 2006 12:06:22 PM Subject: Re: reading commands from a file On 2006-08-23, Khubaib <[EMAIL PROTECTED]> wrote: > hello, i am a good user of VIM, but not very advanced. I use > macros a lot. a frequent one that i use is to comment code in > verilog, C, perl etc. now, i go back and forth frequenty between > various code, and code comment macro (@c) and uncomment macro (@u) > have to be different for perl and C, e.g. Now, what I do is that > everytime I come to C code, i have to redefine the macro (pressing > qc0i//<esc>jq) and next time i go to perl code, i have to do it > again (qc0i#<esc>jq) . > > i was wondering if i can put these keystrokes in a file (e.g. > C_comment.macro and perl_comment.macro), and can source the file > in VIM whenevr i want to. that way, i can put frequently used > macros keystrokes in files, and read those commands at run time in > VIM. any idea how to write that *.macro file (with these > keystrokes)? I tried but <esc> does not work. (i put following > thing in file: qc0i//<esc>jq. now when i source it, it keep > inserting <esc> etc too, which is bugging me). > > summary: what I want to do is that in VIM window, instead of > pressing keystrokes on keyboard, VIM reads the keystrokes (as > exactly if it were from keyboard, including insert mode) from a > file... As Yakov said, there are many ways to do that. Here's one that will let you use the macros you are used to without ever having to enter their definitions again. Put these lines in your ~/.vimrc. au BufEnter * if &ft == "c" | let @c = "0i//\<esc>j" | endif au BufEnter * if &ft == "perl" | let @c = "0i#\<esc>j" | endif Follow the same pattern for your @u macros. Note the backslash in front of <esc> and that the key sequences are in double-quotes ("). See :help expr-string HTH, Gary -- Gary Johnson | Agilent Technologies [EMAIL PROTECTED] | Wireless Division | Spokane, Washington, USA
