Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

in vim, I can set local configuration as

 setlocal number 

How I can set a local match only for specific filetype?

I use this:

 autocmd! BufEnter *.py,.vimrc,*.sh,*.c* :match ColorColumn /\%>80v.\+/

… but when I open a file of another filetype, in the same session, this gives me the match ColorColumn.

share|improve this question

3 Answers 3

This might no longer be useful to the author, but I put the following in .vim/ftplugin/python.vim:

if exists('+colorcolumn')
    setlocal colorcolumn=81
else
    au! BufEnter <buffer> match ColorColumn /\%81v.*/
endif

Since it's in ftplugin, it only occurs for python files, and BufEnter keeps it local to the buffer that the python file is in.

share|improve this answer

with this I solved

augroup longLines
    autocmd! BufEnter *.py,.vimrc,*.sh,*.c* :match ColorColumn /\%>80v.\+/                      
augroup END
share|improve this answer
    
I didn't actually understand your question to the detail, but that doesn't exactly do what you asked for. –  ldigas Nov 13 '11 at 12:52
    
my question is, if I open many files, how activate the match only in some files? –  juanpablo Nov 13 '11 at 15:34
    
"many files" ?? Many files of a certain filetype or by extension or ... ? Filetype is activated by autocmd FileType, BufEnter by opening a buffer. Depends on what you want. Could you try to explain it a bit further? –  ldigas Nov 13 '11 at 19:15
    
many files, some *.py, some *.c, some *.txt –  juanpablo Nov 13 '11 at 20:56
    
See my answer. Is that what you wanted? –  ldigas Nov 13 '11 at 23:46

This will make the highlighting active when python or c filetypes are open (feel free to add the others in there. I didn't know what filetype *.sh extension belongs to), and make it go away for for all the others.

augroup LongLines
    autocmd!
    autocmd FileType * match none
    autocmd FileType python,c,sh match ColorColumn /\%>80v.\+/
augroup END
share|improve this answer
    
*.sh is a bash file, a sh filetype –  juanpablo Nov 14 '11 at 1:22
    
@juanpablo - Updated the answer to include sh. –  ldigas Nov 14 '11 at 1:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.