Khubaib 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...
  thanks for support..
--------------- http://onthethirdside.blogspot.com ----------------





This is the kind of job for an after-plugin.

1. If it doesn't exist, create the directory ~/.vim (on Unix) or ~/vimfiles (on Windows).

2. In the above directory, create the subdirectories after/ and after/ftplugin/ (if they don't yet exist).

3. In the above after/ftplugin/ directory, add the following files (or append to them if they already exist):

-----8<----c.vim
map <buffer> {lhs} {rhs}
----->8----

-----8<-----perl.vim
map <buffer> {lhs} {rhs}
----->8-----

etc., where <buffer> is less-than, b-for-Bravo, u-for-Uniform, f-for-Foxtrot, f-for-Foxtrot, e-for-Echo, r-for-Romeo, greater-than; {lhs} is the key or key sequence you want to press; and {rhs} is your macro (what you want Vim to do). Assuming that you have filetype plugins ON (check ":filetype" with no arguments), the above after-plugins will define buffer-local macros whenever files of the corresponding filetype are opened for editing or viewing.


Best regards,
Tony.

Reply via email to