I just wrote a function which tries to call another function, but I got the syntax wrong. However, I was horrified to see that the next line in my function happily started executing anyway. It is as if every line of my vimscript function has a try-catch around it; oh no! How do I disable this?

For example, try running :call AmendCommit("098ajwe")<CR>. After the failure of the call to FixupCommit, the next line still tries to execute!

fu! FixupCommit(commit_hash)
  execute "Git commit --fixup=" . a:commit_hash

fu! AmendCommit(commit_hash)
  execute "Git rebase --autosquash " . a:commit_hash . "~1"

See :h :func-abort, like

function! AmendCommit(commit_hash) abort

This is recommended practice in the current version of VimScript.

In Vim9Script "abort" is planned to be the default behaviour, and so the word "abort" won't be needed/supported.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.