Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The autocmd pattern to match filename and part of path in Vim

Tags:

vim

autocmd

I am trying to make an auto-cmd triggered by opening a new file with path including test/ and with filename ending in Test.java. Reading in :h autocmd-patterns I can not figure out if either only limited patterns can be used as a file pattern in an auto-cmd or if I am simply doing something wrong with my pattern. The following works for matching any file ending in .java

autocmd! BufNewFile *.java
 \ "command implemented !

Now I try to match new files with a path containing /test/ and with a file name ending in Test.java through the following and derivatives of it

autocmd! BufNewFile */test/*Test.java
 \ "command implemented !

How do I trigger the autocmd on all files having part of their path the test/ folder and the filename ending in Test.java. For instance it should be triggered on doing

$ vim code/algos/graphs/test/KruskalTest.java
like image 705
user847614 Avatar asked Aug 09 '11 17:08

user847614


2 Answers

augroup MyJavaAUGroup
  au! BufRead,BufNewFile,BufEnter *.java,*Test.java,*/test/* <<YOURCOMMANDHERE>>
augroup END
like image 67
John Kaul Avatar answered Nov 16 '22 02:11

John Kaul


Try using the **/test/*Test.java pattern instead. Also, ensure that you chose the correct auto-command event: For the BufNewFile event to be triggered, it is necessary for the file with a given name not to exist.

like image 21
ib. Avatar answered Nov 16 '22 02:11

ib.