With vim, how can I use autocmd's for files in subdirectories of a specific path?

偶尔善良 提交于 2020-03-13 04:50:14

问题


I am trying to figure out how I can define an autocmd that influences all files under a specific path.

The autocmd I have tried is something like

autocmd BufNewFile,BufRead /specificPath/** imap <buffer> ....

Now, I'd expect this autocmd to be used if I edited, say, /foo/bar/specificPath/baz/something/bla.txt, but not if I edited /foo/bar/here/and/there/moreBla.txt

If I start vim being in a directory 'above' specificPath, this works as I want it. But it doesn't if I am below that directory. Obviously, the autocmd's pattern is matched against the relative file name, not the absolute one.


回答1:


So, I've done this in my code with paths under a particular path. You need to do:

autocmd BufRead,BufNewFile */somepath/* set filetype=sometype

At least, that's what I was using to set a given filetype for things under a particular library path. Hopefully that will help with your example.

If you want to include all subdirectories, use **:

autocmd BufRead,BufNewFile */somepath/** set filetype=sometype



回答2:


This will answer all your questions. : )

:h autocmd-patterns


来源:https://stackoverflow.com/questions/2437777/with-vim-how-can-i-use-autocmds-for-files-in-subdirectories-of-a-specific-path

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!