I got an ezmlm warning, so I'm resending. ---------- Forwarded message ---------- From: Eric Arnold <[EMAIL PROTECTED]> Date: May 7, 2006 10:21 PM Subject: Re: Newbie problem: Beginners script pitfall To: Meino Christian Cramer <[EMAIL PROTECTED]> Cc: vim@vim.org
On 5/7/06, Meino Christian Cramer <[EMAIL PROTECTED]> wrote:
From: Gerald Lai <[EMAIL PROTECTED]> Subject: Re: Newbie problem: Beginners script pitfall Date: Sun, 7 May 2006 12:08:46 -0700 (PDT) Hi, thanks a lot for the help! I got the script running...nearly. In my opinion the help system of vim cann't help a newbie to find the things and answers s/he is looking for.
I have to disagree. Vim's help docs are as complete as any I have seen. I suspect your problem is that you are starting from the bottom/middle up, which is fine only when you have a bigger picture in mind.
Often the problem is just the "context" I have to feed into the system to get help. What context ???
The 'context' is the 'bigger picture'. No matter what you're trying to learn, if you haven't read enough to know what you're looking/searching for, then frustration is inevitable. Starting with :help ,a page or so down, you will see: |usr_41.txt| Write a Vim script There are obscure things in Vim that can be hard to find, as with any system, but you haven't hit them yet, and by the time you do, you should be experienced enough to find most all of them.
Example: help script gives me an "Introduction" help scripts shows me, how to debug scripts and helpgrep scripts clist gives me 229 matches.
Have you tried :h normal^D or :h s/^D or :h script^D ?
As newbie...one is lost. A program of the complexity and power of vim deserves something more than grep. What's about an extra user_* file,
That's why Vim help has keywords/tags and hyperlinks.
which shows contexts (what the plural of context?) of certain topics and will combine tags in a contextual manner? As for my last question: How would a newbie guess correctly, that failing with "set history=100" has something to do with "set nocompatible", without knowing that in beforehand ?
The more pain you are feeling the more it should spur you to start from the top and work your way into the docs, i.e. simply :help If you follow the table of contents, it will guide you through all sorts of stuff, including the problems with the [no]compatible option. Unfortunately, with some things like "nocp", there are just too many things to cross-reference with every possible thing, so :help set won't tell you. However, if you did :help history^D and picked the history option, i.e. 'history', then the help for this would have cross-referenced you to 'compatible'. The awful truth is that almost every time I felt lost when I was starting with Vim, it was my fault for not having the patience to start at the top level. As for :helpgrep you got a lot of matches for a common word like 'scripts'. That's expected no matter what the raw text search is. Try 'scripts' on Google :) However, using the command line completion ^D and <TAB>, will show you *keywords*, where the returned list is manageable.
But this is another story. My current problem is: The script combines two consecutive lines of text, which consist of different contents. The second line will be deleted after the contents of both are processed. I want to run the script over an input of different length. The first line has to be skipped (it is the famous "#!/bin/zsh" :O). My problem here is, that the script does not stop corrrectly. As it modifies the length of the text while running, my attempts to pass a range to the script or to determine the range by the script itsself, which would be the better solotion, failed. In Emacs, there is the possibility to stop a looping macro/script automagically when it tries to access something beyond EOF.
looping past EOF in Vim script should never be a problem if you're checking for line("$"). You can also put an error handler around something with try ... catch ... endtry
I found a hint for the abort() command, but help abort said, that This function causes abnormal program termination. despite the fact, that help function states: When the [abort] argument is added, the function will abort as soon as an error is detected. . By the way: <C-]> on [abort] gives me "E426: tag not found [abort] . How can I solve this problem?
You should include the script or script fragments if it is huge. It sounds like you aren't using relative range addresses, i.e 2,$ or .,$ or /#!\/bin\/zsh/+1,$ . Also within the script you can use your own loops: let linenr = 2 while linenr < line("$") let contents = getline(linenr) if ...whatever... let contents = substitute(... call setline(linenr, contents) endif ... let linenr += 1 ...
Thank you very much for any help in advance! mcc
[...]