When a vim script is to be watched for errors and interrupts, try is put somewhere near the beginning and catch after a long sequence of code. In this sequence of code it is very probable to have some condition commands, i.e., if … endif, etc. Now when I type CTRL-C or an error occurs, this happens randomly with respect to the location in code, e.g., after if and before endif. Thus it is natural that catch gives the error message, i.e., missing :endif and terminates the script.

How can I handle this situation in vim?

  • This is not how things should work. If Ctrl-C is received while Vim is executing a statement inside an if..endif block program execution jumps to the catch section (I'm assuming catch is "bare" so it catches all errors). You definitely shouldn't get a missing :endif error. You should double check your code to make sure you don't have any actual syntax type errors.
    – B Layer
    Oct 20 '21 at 20:52
  • thanks for your answer, but my code is not bad, repeated and written in various way 5 days long. even silent, "silent! catch" does not help, error message persists and crash persists, the echo command following catch is not executed, insted the script (from souced file) is terminated unnormall. Oct 21 '21 at 10:06
  • Then it'll be best if you post the code if possible...see if anyone else can reproduce the issue. (If it's too big try to reduce it to a smaller sample that still reproduces the problem.)
    – B Layer
    Oct 21 '21 at 11:12
  • There was a bug on the mailing list recently about try and if, but I don’t recall the details.
    – D. Ben Knoble
    Oct 21 '21 at 11:20
  • According to your advice I have prepared a demo code. Since I do not know how to send a file, I tried to insert it to here, but your message is: 455 charactrts left. Oct 22 '21 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.