捕获中断/中断命令
我试图中断 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试重现您描述的行为我构建了以下内容
测试用例。它包含两个使用该命令创建的相同文件
,并在 Vim 中打开,除了获取文件之外,无需任何初始化
包含
:QFDo
命令的实现:或
在这两个文件中搜索模式,
填充可用于运行
有问题的命令,
在第一个命令之后使用 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
and opened in Vim without any initialization apart from sourcing the file
containing implementation of the
:QFDo
command:or
Searching for a pattern in those two files,
populates the contents of the quickfix window that can be used to run the
command in question,
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 filetmp2
remains untouched. This factmeans 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.