You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Vim的/、?搜索启用smartcase,为*、#搜索启用noic?

嘿,这个需求完全能实现,而且不用重映射*和#,用Vim的自动命令(autocmd)就能精准控制不同搜索场景的大小写规则!

直接把这段配置加到你的~/.vimrc(Neovim用户则是~/.config/nvim/init.vim)里:

" 全局默认:让*和#始终区分大小写
set noignorecase nosmartcase

" 进入/或?搜索命令行时,启用smartcase规则
autocmd CmdlineEnter /,? :set ignorecase smartcase

" 退出搜索命令行后,恢复全局的区分大小写设置
autocmd CmdlineLeave /,? :set noignorecase nosmartcase

为啥这么管用?

  • 全局设置noignorecase nosmartcase,确保普通模式下按*或#时,搜索会严格区分大小写,正好匹配你要的noic效果。
  • 当你按下/或?进入搜索命令行时,CmdlineEnter自动命令会临时开启ignorecase和smartcase——这时候/?搜索就会遵循smartcase逻辑:输入全小写时不区分大小写,只要包含大写字母就严格匹配大小写。
  • 等你退出搜索命令行(比如回车执行搜索、按ESC取消),CmdlineLeave自动命令会把设置切回全局默认,不会影响后续*和#的使用。

这样既不用改默认按键映射,又完美满足了你两种搜索场景的不同需求~

内容的提问来源于stack exchange,提问作者Keith Hanlan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:25:51