Saturday, August 22, 2020

Re: Autocommand script

On Sat, Aug 22, 2020 at 09:01:56AM +0000, A. Wik wrote:
>if has("autocmd")
> au BufLeave * let x=0 | while x<=bufnr('$') |
>\ if bufexists(x) |
>\ set buflisted hidden bufhidden=hide |
>\ endif |
>\ let x = x+1 |
>\ endwhile
>endif " has("autocmd")

>I was wondering...
>(a) if there is a better way to do it than this script...

Can you explain what you're trying to do?

>(b) whether all the backslashes and pipe characters (|) are really
>necessary and why.

The pipe characters are necessary to define a concatenated list of
commands to :autocmd. The backslashes are line-continuation characters
to break up what would otherwise be a long line.

The easiest way to avoid both in this context is to define a function to
group the commands:

function! MyFunction() abort
...
endfunction

if has('autocmd')
autocmd BufLeave * call MyFunction()
endif

--
Tom Ryder <https://sanctum.geek.nz/>
Maybe we can bring back the light.

--
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200822145524.GG16492%40arjuna.sanctum.geek.nz.

No comments: