捕获中断/中断命令

发布于 2024-12-05 15:49:27 字数 907 浏览 0 评论 0原文

我试图中断 for 循环,如下面的代码所示,

for num in buffer_number_list
    " Select the buffer
    exe 'buffer' num
    " Run the command that's passed as an argument
    exe a:command
    " Save if necessary
    update
endfor

而不是仅中断行 exe a:command,当 a:command是一个 :s///命令

目的是更改响应代码 如何进行搜索和在 vim 中替换为 ack?

我尝试用 try/catch 块包围 exe a:command 行, 但它不起作用,可能是因为命令处理了中断 信号而无需重新抛出。

尝试重新映射 CTRL-c 来更改某些变量(将在循环内部检查),但它不起作用:

let original_Ctrl_c = maparg('<c-c>', 'n')
exe 'nnoremap <c-c> :call <SID>BreakLoop()<CR>' . original_Ctrl_c

似乎当中断信号为 捕捉。

有什么想法吗?

编辑:

这个问题似乎只发生在 gVim 中(感谢@ib。)

I'm trying to interrupt a for loop such as in code below,

for num in buffer_number_list
    " Select the buffer
    exe 'buffer' num
    " Run the command that's passed as an argument
    exe a:command
    " Save if necessary
    update
endfor

instead of interrupting only line exe a:command, when a:command is a
:s/// command.

The purpose is to change code on response to How to do search & replace with ack in vim?

I've tried surrounding the line exe a:command with a try/catch block,
but it doesn't worked, probably because the command handled the interrupt
signal without re-throwing it.

Tried remapping CTRL-c to change some variable (which would be checked inside of the loop), but it didn't worked:

let original_Ctrl_c = maparg('<c-c>', 'n')
exe 'nnoremap <c-c> :call <SID>BreakLoop()<CR>' . original_Ctrl_c

It seems that the mapping didn't trigger when the interrupt signal is
caught.

Any ideas?

EDIT:

It seems that this problem only occurs in gVim (thanks @ib.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疑心病 2024-12-12 15:49:27

尝试重现您描述的行为我构建了以下内容
测试用例。它包含两个使用该命令创建的相同文件

$ echo -e "skip\npat\npat" | tee tmp1 >tmp2

,并在 Vim 中打开,除了获取文件之外,无需任何初始化
包含 :QFDo 命令的实现:

$ vim -u NONE -S qfdo.vim

$ gvim -u NONE -U NONE -S qfdo.vim

在这两个文件中搜索模式,

:vimgrep /pat/ tmp{1,2}

填充可用于运行
有问题的命令,

:QFDo v/skip/s/pat/rep/gce

在第一个命令之后使用 Ctrl+C 中断此命令
替换(恰好位于文件 tmp1 中)终止了整个过程
:QFDo 命令,因此文件 tmp2 保持不变。这个事实
意味着您试图克服的行为是由某些 .vimrc 引起的
定制或插件。定位实际配置损坏的地方
Ctrl+C 行为,禁用所有插件并尝试
让他们每次都一一运行上述测试用例。

Trying to reproduce the behavior you describe I have constructed the following
test case. It includes two identical files created using the command

$ echo -e "skip\npat\npat" | tee tmp1 >tmp2

and opened in Vim without any initialization apart from sourcing the file
containing implementation of the :QFDo command:

$ vim -u NONE -S qfdo.vim

or

$ gvim -u NONE -U NONE -S qfdo.vim

Searching for a pattern in those two files,

:vimgrep /pat/ tmp{1,2}

populates the contents of the quickfix window that can be used to run the
command in question,

:QFDo v/skip/s/pat/rep/gce

Interrupting this command using Ctrl+C after the first
replacement, which occurs to be in the file tmp1, terminates the whole
:QFDo command, and therefore the file tmp2 remains untouched. This fact
means that the behavior you are trying to overcome is caused by some .vimrc
customization or plugin. To locate the actual configuration breaking
Ctrl+C behavior, disable all of the plugins and try
enabling them one by one running the above test case each time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文