如果完整文件名不包含模式,请运行自动命令(Run autocommand if full file name does not include pattern)

编程入门 行业动态 更新时间:2024-10-27 10:33:24
如果完整文件名不包含模式,请运行自动命令(Run autocommand if full file name does not include pattern)

每次我保存一个python文件时,我都有一个运行flake8的函数。 但是,如果完整文件名(完整路径)包含/.git/ ,我不希望该函数运行。 我怎样才能做到这一点? 我尝试了以下但未成功:

au BufWritePost */[^git]/*.py call s:MyFlake8()

I have a function to run flake8 every time I save a python file. However I don't want that function to run if the full file name (full path) includes /.git/. How can I achieve that? I tried the following without success:

au BufWritePost */[^git]/*.py call s:MyFlake8()

最满意答案

如果条件不符合,我会在MyFlake8顶部进行提前检查并退出。

function! MyFlake8() if expand("%:p") =~ "/\\.git/" return endif echo "FLAKE8!" endfunction au BufWritePost *.py call s:MyFlake8()

I'd do an early check at top of MyFlake8 and exit if conditions are not met.

function! MyFlake8() if expand("%:p") =~ "/\\.git/" return endif echo "FLAKE8!" endfunction au BufWritePost *.py call s:MyFlake8()

更多推荐

本文发布于:2023-08-07 13:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464777.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件名   不包含   命令   完整   模式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!