Sunday, December 13, 2020

Re: Vim-script question

On 12/10/20 4:03 PM, 'Klaus Jantzen' via vim_use wrote:
> Hi,
>
> I want to include in my .vimrc an autocommand that writes some new
> lines into an empty file e.g. an zsh script.
>
> So I wrote
>
> au  BufNewFile *.zsh :a "#! /usr/bin/zsh"
>
> but that does not do what I want (it does not do anything).
>
> So my question: How can I write with the autocommand one or more lines
> into an empty buffer?
>
> Thanks for your help.
>
Hi,

thank you very much for your very helpful information. Now I have a much
better understanding of vimscript.

The following shows what I finally wrote

===
function NewZshScript()
    let ts = " generated on " . strftime('%Y-%m-%d at %H:%M:%S')
    let inf = expand("%") . ts
    0put ='#! /usr/bin/zsh'
    put ='#'
    put ='# ' . inf
    put ='#'
    put ='pn=$1'
    put ='pn=${pn##*/}'
    put ='#'
endfunction
au BufNewFile *.zsh call NewZshScript()

===

First I tried 'append' but I never get that working with the line
continuations. Besides the function gives me more flexibility.

Here doc or stubs I will try when I have a bigger template.

Thank you.

--

K.D.J.

--
--
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/17c00fdf-f576-1114-e987-a846ad94081d%40mailbox.org.

No comments:

Post a Comment