Thursday, February 25, 2016

Re: How to write autocmd command to set local variable to some value when new buffer is created?

@Ben, thank you for your kind reply.

I tried to do the following:
1. In my $MYVIMRC file I put only:
:set nocompatible
2. In my $MYGVIMRC I have deleted all content, so there is empty file.
3. Started gVIM.
4. Typed in command:
:source commentary.vim
:autocmd BufNew * setlocal commentstring=--\ %s
5. New buffer:
:enew!
6. Typed in some text.
7. Comment out a line:
gcc
And it works fine. Comment string at front of line is: --


Then I did the following:
1. In my $MYVIMRC file I put only:
:set nocompatible
:source commentary.vim
:autocmd BufNew * setlocal commentstring=--\ %s
2. $MYGVIMRC I have put empty as before.
3. Closed gVim and strated it again to make sure $MYVIMRC file was read.
4. New file:
:enew!
5. Typed in some text.
6. comment out a line:
gcc
And it does not work as expected. It sets: /* text */ commemnt.
7. I tried to get more info about this string as you suggested:
:verbose set commentstring?
and output is:
commentstring=-- %s
Last set from ~\_vimrc

Note: ~\_vimrc is file $MYVIMRC.
Don't understand why???


The only work-around I have found now is to replace "BufNew" with "BufEnter" in autocmd command inside $MYVIMRC file, restarted gVim and then it works fine.
It is still mistery to me why BufNew does not have effect in my case and BufEnter has. Any idea how to debug?

Thanks

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment