Hi, While we are at the subject of tips for budding Vim scripters - I had created this mapping -->
nmap com ^:if search('\/\*.*\*\/','c',line("."))!=0<CR> :.s/\/\*\(.*\)\*\//\1/g<CR> :else<CR> :.s/\(\s*\)\(.*\)\(\s*\)/\1\/\*\2\*\/\3/g<CR> :endif<CR> :noh<CR> this command basically toggles C-style commenting on a line i.e. if the line wasn't commented it comments out the entire line and vice-versa. I spent an intense hour of exploring the help pages and plenty of effort in trial and error before I could reach the 'Eureka' moment. What I wanted to know is could the same functionality have been achieved by a better sequence of commands? Can an experienced 'vimmer' do better? Regards, Sibin -----Original Message----- From: Mikolaj Machowski [mailto:[EMAIL PROTECTED] Sent: Sunday, December 03, 2006 7:18 PM To: vim@vim.org Subject: Re: your best vim scripting tip On nie gru 3 2006, vim@vim.org wrote: > Hi, > It you should give one (or more) tips to a person who was going to > start creating scripts for vim, then what would it be? > (besides "know your :help" :-) ) > > ideas could be: > Do's and dont's Keep ff=unix . In other case your scripts won't be working under non windows systems. Always supply modeline to make sure basic editing things will be working for others. When changing options use setlocal not set - be polite to user environment. Try to cut on g:variables (see above). Try to maintain documentation, not only for use of script but also for messing with it. > best util script Each script covers only part of Vim functionality. It is hard to say which one is best for learning. > often used functions It depends on what are you want to achieve. > ways of optimization Avoid \| in complex regexps, often two, separate substite() are faster than one substite() with \|. Avoid * whenever possible, try to use \+ if appropriate. \x class is faster than [collection] When doing complex substitutions it is often faster to check if some part of pattern already exists and only if this is true execute substitution. m. -- I am social scientist - I don't know the difference between good and bad, only the difference between difference. DISCLAIMER: This message (including attachment if any) is confidential and may be privileged. Before opening attachments please check them for viruses and defects. MindTree Consulting Limited (MindTree) will not be responsible for any viruses or defects or any forwarded attachments emanating either from within MindTree or outside. If you have received this message by mistake please notify the sender by return e-mail and delete this message from your system. Any unauthorized use or dissemination of this message in whole or in part is strictly prohibited. Please note that e-mails are susceptible to change and MindTree shall not be liable for any improper, untimely or incomplete transmission.