Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I make open files as readonly and nomodifiable, if they're in a certain folder hierarchy, but do NOT contain a certain extension?

For example, if I open files on /server/(production|uat)/* I want to be prompted whether to edit the file, or just view it. An exception might be needed as well--such as if the file contains the prefix temp.

share|improve this question
    
You could replace your vim executable (at 'which vim') with a bash script that executes vim -R -M instead of vim if your conditions are met –  user247679 Aug 28 '13 at 21:01

1 Answer 1

Put this into your .vimrc file:

autocmd BufReadPre,BufNewFile /Taboo/Dir/*  setlocal readonly nomodifiable
autocmd! BufReadPre,BufNewFile /Taboo/Dir/*/temp*.txt   setlocal noreadonly modifiable
share|improve this answer

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.