在 vi 中编辑 bash 脚本时跳转到匹配 "done"

Jump to matching "done" while editing bash script in vi

在 vi 中,% 键可用于跳转到匹配的左括号或右括号、方括号或大括号。

是否也可以用于在 bash 循环中匹配 "do" 和 "done" 之间跳转?

不是 "vi" 这样的。 vim 这样做。 有一个脚本 matchit.vim 可以做到这一点:

进一步阅读:

  • Vim: Jumping to if endif in fortran 仅使用 runtime macros/matchit.vim 而不是 vim wiki 中的两部分安装。
  • Matchit not working 有几个答案,有些不同意。

~/.vimrc 中的 runtime macros/matchit.vim 行在我的快速测试中没有使 matchit.vim 工作; matchit-install 中的过程加上 filetype 行确实有效。与往常一样,您的配置可能有所不同。

我在文档中维护(当然也使用)vi-like-emacs, and wrote comparable functionality for that editor using a different approach (see discussion of "fences")。在快速测试中,我看到 matchit.vim 不知道 shell case 语句中 case-values 的语法。所以还有一些改进的空间。