Wikia

Vim Tips Wiki

Changes: Automatic file type detection with fully qualified ClearCase names

Edit

Back to page

(Adjust previous/next navigation)
(Remove html character entities)
 
Line 16: 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 25: 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==

Latest revision as of 05:40, September 29, 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>

ReferencesEdit

See alsoEdit

script#15 combines well with this tip.

CommentsEdit

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

Around Wikia's network

Random Wiki