Vim Tips Wiki
(More manual cleaning to standardise format)
(Remove html character entities)
(3 intermediate revisions by 2 users not shown)
Line 2: Line 2:
 
|id=364
 
|id=364
 
|previous=363
 
|previous=363
|next=365
+
|next=366
 
|created=November 8, 2002
 
|created=November 8, 2002
 
|complexity=basic
 
|complexity=basic
Line 8: Line 8:
 
|version=6.0
 
|version=6.0
 
|rating=28/13
 
|rating=28/13
 
|category1=VersionControl
  +
|category2=
 
}}
 
}}
 
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.
 
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.
Line 14: Line 16:
 
augroup filetypedetect
 
augroup filetypedetect
 
au BufNewFile,BufRead *@@/*
 
au BufNewFile,BufRead *@@/*
\ if expand("<afile>") =~ '@@' |
+
\ if expand("<afile>") =~ '@@' |
\ exe "doau filetypedetect BufRead " . expand("&lt;afile&gt;:s?@@.*$??") |
+
\ exe "doau filetypedetect BufRead " . expand("<afile>:s?@@.*$??") |
 
\ endif
 
\ endif
 
augroup END
 
augroup END
Line 23: Line 25:
   
 
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:
 
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:
<pre>autocmd FileType c,cpp &lt;command&gt;</pre>
+
<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:
 
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{@@/*,} &lt;command&gt;</pre>
+
<pre>autocmd BufWinEnter *.c{@@/*,} <command></pre>
   
 
==References==
 
==References==
 
*{{help|new-filetype}}
 
*{{help|new-filetype}}
   
==See Also==
+
==See also==
 
{{script|id=15}} combines well with this tip.
 
{{script|id=15}} combines well with this tip.
   
 
==Comments==
 
==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:
  +
<pre>
  +
augroup filetypedetect
  +
au BufNewFile,BufRead *
  +
\ if expand("<afile>:p") =~ '@@' && expand("<afile>:t") !~ '@@' |
  +
\ exe "doau filetypedetect BufRead " . substitute(expand("<afile>:p"),'@@.\{-\}$','','') |
  +
\ endif
  +
augroup END
  +
</pre>
   
 
----
 
----
[[Category:VersionControl]]
 

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