On 06/02/10 02:25, Girish Venkatasubramanian wrote:
Hello,
I decided to make me a nice vimrc file. But I am stuck at two spots
and will appreciate any advice/tips on how to get these working.

1) Automatic retab (What I would like to do is to automatically retab
every file that I open). Initially, I had

if has("autocmd")
     au BufReadPost * retab
endif

but this complained when I was opening unmodifiable buffers like
"help:retab". Then I changed this to
if&modifiable
   if has("autocmd")
       au BufReadPost * retab
   endif
endif

but still executing "help:retab" complains about
Error detected while processing BufRead Auto commands for "*":
E21: Cannot make changes, 'modifiable' is off: retab

I am currently working around this by asking vimrc to retab only
specific types of files like *c, *cpp etc

2) I can reformat the entire document according to my formatoptions by
gggq<Shift+g>. Is there any way I can do this from vimrc instead of
manually typing n the command every time I open a file?

Thanks.


An answer has been given, but what you're requesting here makes me shudder: except for 'nomodifiable' files, but for all other files including 'readonly' ones (either because the medium is readonly, or the file has readonly attributes, or even because you opened it with :view rather than :edit for the exact purpose of _not_ changing it) the first thing that Vim will do, without asking for confirmation, is modify the files by changing tabs to spaces or vice-versa, and even reformatting the text, and that all over the place! When I use Vim to examine its own sources (for example), I don't want it to change any file one single bit without my positive, explicit and specific say-so (which I don't "say" very often), and even if I do change a bit of code here or there to test a proposed bugfix, I wouldn't dream to meddle with Bram's coding style at the risk of making all future patches fail (because they are based on whatever there used to be, and are unaware of any "reformatting").

One slightly better solution (than the answer you got) would be to write the autocommand as (for example)

        :au BufReadPost * if &ma && ! &ro | DoSomething | endif

but IMHO it would really be better to have no automatic action at all, but, let's say,

        :map <F6>   :retab<CR>
        :map <S-F6> gggqG

(or vice-versa if you think you reformat oftener than retab, or any other {lhs} that strikes your fancy) so Vim would not clobber each and every file that it opens, but you're still only one keypress away from your favourite reformatting when you _really_ want it.


Best regards,
Tony.
--
"... the Mayo Clinic, named after its founder, Dr. Ted Clinic ..."
                -- Dave Barry

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

To unsubscribe, reply using "remove me" as the subject.

Reply via email to