gpt4 book ai didi

vim - 如何仅在 Vim 中没有打开快速修复窗口时启用映射?

转载 作者:行者123 更新时间:2023-12-02 19:55:56 25 4
gpt4 key购买 nike

我想在打开快速修复窗口时禁用以下映射。

map <F5> :ZoomWin<cr>

最佳答案

您指的是快速修复吗?如果是这样,有以下三种方法:

  1. 使用<expr>映射:

    nnoremap <expr> <F5> (&buftype is# "quickfix" ? "" : ":\<C-u>ZoomWin\n")
  2. 使用 BufEnter 事件设置/恢复映射:

    augroup F5Map
    autocmd! BufEnter * :if &buftype is# 'quickfix' | nunmap <F5> | else | nnoremap <F5> :<C-u>ZoomWin<CR> | endif
    augroup END
  3. 仅为需要的缓冲区在本地创建映射:

    augroup F5Map
    autocmd! BufEnter * :if &buftype isnot# 'quickfix' && empty(maparg('<F5>')) | nnoremap <buffer> <F5> :<C-u>ZoomWin<CR> | endif
    augroup END

更新:要在任何打开的窗口包含 QuickFix 缓冲区时禁用映射,请使用以下命令:

nnoremap <expr> <F5> (&buftype is# "quickfix" || empty(filter(tabpagebuflist(), 'getbufvar(v:val, "&buftype") is# "quickfix"')) ? ":\<C-u>ZoomWin\n" : "")

关于vim - 如何仅在 Vim 中没有打开快速修复窗口时启用映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13208660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com