From: "Marius Roets" <[EMAIL PROTECTED]> Subject: Re: How to insert text via script/function call ? Date: Fri, 18 Aug 2006 09:52:42 +0200
> On 8/18/06, Meino Christian Cramer <[EMAIL PROTECTED]> wrote: > > Hi, > > > > I often need to place a header above a function defintion (C-source) > > fpr documentational purposes. > > > > What I treid is to write a short function for vim, which dioes insert > > the text skeleton -- but I did not find any already existing function > > in the API which does this for me. With :i I got weird effects -- > > sure my fault, but... . > > > > How can I insert text via a script ? > > > > Kind regards, > > mcc > > > > Hi > I got this in my .vimrc: > > function! ReadSkeleton() > > if exists ("g:Skeleton_path") > let skeleton_path = g:Skeleton_path > else > let skeleton_path = getcwd() > endif > > let filenameList = split (glob ( skeleton_path . "/*.*") , "\n") > let filenameList = insert (filenameList, "Select skeleton to load") > let choiceList = copy (filenameList) > let choiceList = map (choiceList, 'index(filenameList,v:val) .". ". v:val') > let choiceList[0] = "Select skeleton to load" > let listLen = len(choiceList) > let choiceList = add (choiceList, listLen . ". Browse for some > other folder (gui ONLY)") > let choice = inputlist(choiceList) > "echo choice > let skeletonName = "" > if choice == listLen > "Do the browse thingie if possible > if has("browse") > let skeletonName = browse(0,"Select session to > restore",skeleton_path,"") > "echo skeletonName > endif > elseif choice > 0 > "Load the file > let skeletonName = filenameList[choice] > " echo "setting skeletonName to ". skeletonName > endif > if skeletonName != "" > execute "0read " . skeletonName > endif > endfunction > nmap <F4> :call ReadSkeleton()<cr> > let Skeleton_path = "/home/mroets/.vim/skeletons" > > I put all the skeletons for programs (perl, c , php etc), each in > their own file in a directory, and set Skeleton_path to this directory > in my .vimrc. Now I press F4 and choose which skeleton I want for my > new file. > > HTH > Marius > Hi Marius! thank you for your reply and the script ! That's far more that I ever want ! :) I was simply for an aquivalent to printf( "This is my text!" ) but instead of C and printing via stdout it should be vim script and the text should go right to the current cursor position. That's all! Keep hacking! mcc