On 11/11/11 15:34, Taylor Hedberg wrote:
I'm running into some strange behavior with autocommands, using Vim 7.3.353. I'm not sure whether it's a bug, or just one of those "gotchas" that seem to pop up throughout Vim's syntax.I have a command defined as follows: command! WinWidth execute 'vertical resize' (&textwidth + 1) I want the command to be automatically executed when I enter a window in which w:winwidth is 1. So I wrote: autocmd WinEnter * if exists(w:winwidth)&& w:winwidth | WinWidth | endif But whenever the autocommand triggers, I get: E488: Trailing characters: WinWidth | endif This doesn't make sense to me, as WinWidth doesn't take any arguments, nor am I passing any. Somehow, the `| endif` is being interpreted as arguments to the command. But if I rewrite it like this, it works: function! s:auto_win_width() if exists(w:winwidth)&& w:winwidth WinWidth endif endfunction autocmd WinEnter * call s:auto_win_width() So it seems that there is some problem with using a user-defined command in a single-line series of commands, separated by '|'s (if I replace the `WinWidth` with something built-in, like `echo 'foo'`, it works in both cases). Is this some obscure special case of Vim's syntax or is it just a bug?
You forgot to set the -bar switch in the definition of WinWidth, therefore it cannot be followed by | and another command.
See :help :command-bar Best regards, Tony. -- What I want is all of the power and none of the responsibility. -- 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
