Vim Tips Wiki
No edit summary
 
(Remove html character entities)
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  +
{{TipImported
{{review}}
 
{{Tip
 
 
|id=364
 
|id=364
  +
|previous=363
|title=Automatic file type detection with fully qualified ClearCase names
 
  +
|next=366
|created=November 8, 2002 1:47
+
|created=November 8, 2002
 
|complexity=basic
 
|complexity=basic
 
|author=Arnaud Cassignol
 
|author=Arnaud Cassignol
 
|version=6.0
 
|version=6.0
 
|rating=28/13
 
|rating=28/13
  +
|category1=VersionControl
|text=
 
  +
|category2=
I am using the great plugin from Douglas Potts ([/scripts/script.php?script_id=15 vimscript #15]).
 
 
}}
 
When using ClearCase for versioning, often you will view a specific version of a file like filename.c@@\main\branch\42. Vim cannot correctly identify the file type from this full name. To fix this, you can create an autocommand in the filetype.vim file in your user runtime directory.
   
  +
<pre>
 
augroup filetypedetect
 
au BufNewFile,BufRead *@@/*
 
\ if expand("<afile>") =~ '@@' |
 
\ exe "doau filetypedetect BufRead " . expand("<afile>:s?@@.*$??") |
 
\ endif
  +
augroup END
  +
</pre>
   
  +
The "doau" command is executed conditionally for compatibility with non-ClearCase paths that actually contain a '@@' sequence.
   
  +
If you have any other autocmds set up for certain file extensions, you'll need to adjust them as well to account for ClearCase. If possible, using a FileType event can simplify things, since this is set automatically above. For example:
When you load a specific ClearCase version of a file, vim cannot find the correct file type in the full name (ex. filename.c@@/main/foo/1). To improve that, you can create an autocommand in the filetype.vim file in your user runtime directory.
 
  +
<pre>autocmd FileType c,cpp <command></pre>
   
  +
If you actually want to trigger off specific file extensions rather than file types, you'll need to add the pattern used above for detecting clearcase files. For example, to trigger only on .c files:
  +
<pre>autocmd BufWinEnter *.c{@@/*,} <command></pre>
   
  +
==References==
  +
*{{help|new-filetype}}
   
  +
==See also==
augroup filetypedetect
 
  +
{{script|id=15}} combines well with this tip.
   
 
==Comments==
au BufNewFile,BufRead */*@@*
 
  +
This used to work great, but when I upgraded my version of Vim, for some reason file detection stopped working. I did the following to fix it. I don't want to merge it yet, because I'm not entirely sure WHAT fixed it, so eventually I'm going to figure out what parts of my fix are not needed and merge only the necessary ones into the solution above. In the meantime, here's a fix:
 
  +
<pre>
\ if expand("&lt;afile&gt;") =~ '@@' |
 
  +
augroup filetypedetect
 
  +
au BufNewFile,BufRead *
\ exe "doau filetypedetect BufRead " . expand("&lt;afile&gt;:s?@@.*$??") |
 
  +
\ if expand("<afile>:p") =~ '@@' && expand("<afile>:t") !~ '@@' |
 
  +
\ exe "doau filetypedetect BufRead " . substitute(expand("<afile>:p"),'@@.\{-\}$','','') |
\ endif
 
  +
\ endif
 
augroup END
+
augroup END
  +
</pre>
 
 
 
The test in the command is for compatibility with path containing '@@' sequence.
 
}}
 
   
  +
----
== Comments ==
 
<!-- parsed by vimtips.py in 0.438987 seconds-->
 

Revision as of 05:40, 29 September 2008

Tip 364 Printable Monobook Previous Next

created November 8, 2002 · complexity basic · author Arnaud Cassignol · version 6.0


When using ClearCase for versioning, often you will view a specific version of a file like filename.c@@\main\branch\42. Vim cannot correctly identify the file type from this full name. To fix this, you can create an autocommand in the filetype.vim file in your user runtime directory.

augroup filetypedetect
 au BufNewFile,BufRead *@@/*
 \ if expand("<afile>") =~ '@@' |
 \ exe "doau filetypedetect BufRead " . expand("<afile>:s?@@.*$??") |
 \ endif
augroup END

The "doau" command is executed conditionally for compatibility with non-ClearCase paths that actually contain a '@@' sequence.

If you have any other autocmds set up for certain file extensions, you'll need to adjust them as well to account for ClearCase. If possible, using a FileType event can simplify things, since this is set automatically above. For example:

autocmd FileType c,cpp <command>

If you actually want to trigger off specific file extensions rather than file types, you'll need to add the pattern used above for detecting clearcase files. For example, to trigger only on .c files:

autocmd BufWinEnter *.c{@@/*,} <command>

References

See also

script#15 combines well with this tip.

Comments

This used to work great, but when I upgraded my version of Vim, for some reason file detection stopped working. I did the following to fix it. I don't want to merge it yet, because I'm not entirely sure WHAT fixed it, so eventually I'm going to figure out what parts of my fix are not needed and merge only the necessary ones into the solution above. In the meantime, here's a fix:

augroup filetypedetect
  au BufNewFile,BufRead *
        \ if expand("<afile>:p") =~ '@@' && expand("<afile>:t") !~ '@@' |
        \   exe "doau filetypedetect BufRead " . substitute(expand("<afile>:p"),'@@.\{-\}$','','') |
        \ endif
augroup END