Thursday, October 22, 2015

Re: how to find line in vim function

On Thu, Oct 22, 2015 at 4:32 AM, John Zhao <johnzzhao@gmail.com> wrote:
> I am writing a large vim function. When I call it from a .sh script, I got the following error:
>
> clone_all_instances: syntax error at line 518: `}' unexpected
>
> How can I find the line in the function file clone_all_instances?
>
> Thanks for any helps on this one!
>
> John

I'm not sure if "line 518" is counted from the start of the script or
from the start of the function, but you can find out.

1.
:verbose function clone_all_instances

will tell you (under the name of the function) where it was defined.
Write it down before touching the keyboard.

2. Hit the spacebar, then if necessary repeat slowly until you come to
either line 518 or the end of the function (whichever happens first).
If the function has a line 518, and it contains one or more }
characters, this might be the point where Vim detects the error
(however the "real" error may be somewhere higher).

3. If step 2 gave nothing, try
:e +518 /path/to/something.vim
where /path/to/something.vim is the full path to the script, which you
wrote down at step 1. Check if there is a } in that line.

4. If step 2 gave something, try
:e +/\<function\s\+clone_all_instances\> /path/to/something.vim
where /path/to/something.vim is again the full path to the script; then
518j
should bring you near the line you found at step 2 (or maybe a line or
two above or below it). The "magic string" after :e means «find a line
containing the following:
- start-of-word
- the string "function"
- one or more spaces and/or tabs
- the string "clone_all_instances"
- end-of-word
in the script whose pathfilename comes after».

5. After either step 3 or step 4, place your cursor on the } and hit
the % key. Vim will either bring you to what it thinks is the
corresponding { or (if it doesn't find a matching { ) leave the cursor
where it is and possibly give an error.

6. From here on you should be able to find out what was wrong, and correct it.


Best regards,
Tony.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment