Re: How to insert text via script/function call ?
Meino Christian Cramer wrote: No, sorry...I was simply searching for a function call like printf( This is my text! ) Hi Tony, this works so far...with an unwanted sideeffekt: Instead of This is my text! in my buffer I get This is my text!Esc in my text. Have you tried put ='This is my text!' yet? Regards, Chip Campbell
Re: How to insert text via script/function call ?
put ='This is my text!' Yup! it works fine...next is to solve the problem to put a combination of fixed text and the contents of a variable, which contains for example the date-string onmto one line. That's just an evaluated expression there, so you can use :put ='Today is: '.strftime('%c') or :let x = 3+1+4+1+5+9 :put ='sum: ' . x or other more complex expresions. -tim
Re: How to insert text via script/function call ?
Meino Christian Cramer wrote: From: Charles E Campbell Jr [EMAIL PROTECTED] Subject: Re: How to insert text via script/function call ? Date: Tue, 22 Aug 2006 13:33:26 -0400 Yup! it works fine...next is to solve the problem to put a combination of fixed text and the contents of a variable, which contains for example the date-string onmto one line. thanks a lot! mcc put ='Header ' . variable . ' trailer' see :help expression-syntax Best regards, Tony.
Re: How to insert text via script/function call ?
From: A.J.Mechelynck [EMAIL PROTECTED] Subject: Re: How to insert text via script/function call ? Date: Tue, 22 Aug 2006 19:43:59 +0200 OH YEAH! Thanks to you all for all the superfast responses to my variable-question! This was really a HowTo-explosion, hahahahaha !!! :):) :O) Keep hacking! mcc Meino Christian Cramer wrote: From: Charles E Campbell Jr [EMAIL PROTECTED] Subject: Re: How to insert text via script/function call ? Date: Tue, 22 Aug 2006 13:33:26 -0400 Yup! it works fine...next is to solve the problem to put a combination of fixed text and the contents of a variable, which contains for example the date-string onmto one line. thanks a lot! mcc put ='Header ' . variable . ' trailer' see :help expression-syntax Best regards, Tony.
Re: How to insert text via script/function call ?
On 2006-08-22, Meino Christian Cramer [EMAIL PROTECTED] wrote: Yup! it works fine...next is to solve the problem to put a combination of fixed text and the contents of a variable, which contains for example the date-string onmto one line. let date = strftime(%x) put ='Today''s date is '.date.' where I live.' HTH, Gary -- Gary Johnson | Agilent Technologies [EMAIL PROTECTED] | Wireless Division | Spokane, Washington, USA
Re: How to insert text via script/function call ?
From: A.J.Mechelynck [EMAIL PROTECTED] Subject: Re: How to insert text via script/function call ? Date: Sat, 19 Aug 2006 07:47:11 +0200 Meino Christian Cramer wrote: From: A.J.Mechelynck [EMAIL PROTECTED] Subject: Re: How to insert text via script/function call ? Date: Fri, 18 Aug 2006 18:05:13 +0200 Meino Christian Cramer wrote: From: A.J.Mechelynck [EMAIL PROTECTED] Subject: Re: How to insert text via script/function call ? Date: Fri, 18 Aug 2006 07:29:05 +0200 Meino Christian Cramer 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 If your text is in a file on its own, you can use :r with a line number (the number of the line after which to insert, or 0 for before first line, or . for after cursor line, or $ for after last line; default is after cursor line) in the range position, i.e. just before the r. The file name comes as an argument at the end. Example (after line 5): 5r ~/template.txt If your text is in a register, you can use :put with a line number (again) in the range position and the register name (including , which must be escaped as \, for the default register; or + for the system clipboard) after the :put. Example (before cursor line): .-1put \ See :help :read :help :put Best regards, Tony. Hi Tony, thank you for your reply ! :) No, sorry...I was simply searching for a function call like printf( This is my text! ) but instead of C and printing onto stdout it should be vim-script and the text should go right at the current cursor position. Thats all. No registers, no script magic, not extra files. Simply put a string after the cursor into the text. Keep hacking! mcc (Untested): Characterwise: exe normal aThis is my text!\Esc Linewise: exe normal oThis is my text!\Esc If I didn't goof, you can paste one of the above lines straight into your script (via the clipboard). Best regards, Tony. Hi Tony, this works so far...with an unwanted sideeffekt: Instead of This is my text! in my buffer I get This is my text!Esc in my text. I get the text properly inserted. Are you sure that you used double quotes around the string and that it ended (before the closing double quote) with backslash, less-than, E-for-Echo, s-for-Sierra, c-for-Charlie, greater-than ? If it didn't, then you didn't use the lines above by copy-paste as I told you. Or else, maybe you have 'compatible' set? (check it by :verbose set compatible? without the quotes but with the question mark). When using exe normal aThis is my text!\Esc instead, vim says in the commandline: E121: Undefined variable: Esc E15 Invalid expression: normalaThis is my textEsc . No way out ? Kind regards, mcc Try :exe normal aThis is my text!\e and make sure that you use double quotes, not single quotes. see :help expr-string Best regards, Tony. Hi Tony, thanks again your help ! :) Yes, I did a mistake (copy'n'waste does not work from Emacs, which I use as mailclient using Mew, to the vim, so I had to type it in myself) -- I forgot the backslash. With backslash everything works fine! Have a nice weekend! mcc
Re: How to insert text via script/function call ?
On 2006-08-18, Meino Christian Cramer [EMAIL PROTECTED] wrote: 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! put='This is my text!' There you go. Simple. Straightforward. Don't forget to use single quotes (') and not double quotes (). See :help :put Regards, Gary -- Gary Johnson | Agilent Technologies [EMAIL PROTECTED] | Wireless Division | Spokane, Washington, USA
Re: How to insert text via script/function call ?
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
Re: How to insert text via script/function call ?
On Fri, Aug 18, 2006 at 04:44:26AM +0200, Meino Christian Cramer 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 One way to do this is the ClassHeader() function (and associated map/autocommand) in my file of example vim functions, foo.vim : http://www.vim.org/script.php?script_id=72 This one is pretty old: I wrote it before there were such things as buffer-local mappings and ftplugins. HTH --Benji Fisher
Re: How to insert text via script/function call ?
From: A.J.Mechelynck [EMAIL PROTECTED] Subject: Re: How to insert text via script/function call ? Date: Fri, 18 Aug 2006 07:29:05 +0200 Meino Christian Cramer 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 If your text is in a file on its own, you can use :r with a line number (the number of the line after which to insert, or 0 for before first line, or . for after cursor line, or $ for after last line; default is after cursor line) in the range position, i.e. just before the r. The file name comes as an argument at the end. Example (after line 5): 5r ~/template.txt If your text is in a register, you can use :put with a line number (again) in the range position and the register name (including , which must be escaped as \, for the default register; or + for the system clipboard) after the :put. Example (before cursor line): .-1put \ See :help :read :help :put Best regards, Tony. Hi Tony, thank you for your reply ! :) No, sorry...I was simply searching for a function call like printf( This is my text! ) but instead of C and printing onto stdout it should be vim-script and the text should go right at the current cursor position. Thats all. No registers, no script magic, not extra files. Simply put a string after the cursor into the text. Keep hacking! mcc
Re: How to insert text via script/function call ?
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
Re: How to insert text via script/function call ?
Meino Christian Cramer wrote: From: A.J.Mechelynck [EMAIL PROTECTED] Subject: Re: How to insert text via script/function call ? Date: Fri, 18 Aug 2006 07:29:05 +0200 Meino Christian Cramer 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 If your text is in a file on its own, you can use :r with a line number (the number of the line after which to insert, or 0 for before first line, or . for after cursor line, or $ for after last line; default is after cursor line) in the range position, i.e. just before the r. The file name comes as an argument at the end. Example (after line 5): 5r ~/template.txt If your text is in a register, you can use :put with a line number (again) in the range position and the register name (including , which must be escaped as \, for the default register; or + for the system clipboard) after the :put. Example (before cursor line): .-1put \ See :help :read :help :put Best regards, Tony. Hi Tony, thank you for your reply ! :) No, sorry...I was simply searching for a function call like printf( This is my text! ) but instead of C and printing onto stdout it should be vim-script and the text should go right at the current cursor position. Thats all. No registers, no script magic, not extra files. Simply put a string after the cursor into the text. Keep hacking! mcc (Untested): Characterwise: exe normal aThis is my text!\Esc Linewise: exe normal oThis is my text!\Esc If I didn't goof, you can paste one of the above lines straight into your script (via the clipboard). Best regards, Tony.
Re: How to insert text via script/function call ?
From: A.J.Mechelynck [EMAIL PROTECTED] Subject: Re: How to insert text via script/function call ? Date: Fri, 18 Aug 2006 18:05:13 +0200 Meino Christian Cramer wrote: From: A.J.Mechelynck [EMAIL PROTECTED] Subject: Re: How to insert text via script/function call ? Date: Fri, 18 Aug 2006 07:29:05 +0200 Meino Christian Cramer 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 If your text is in a file on its own, you can use :r with a line number (the number of the line after which to insert, or 0 for before first line, or . for after cursor line, or $ for after last line; default is after cursor line) in the range position, i.e. just before the r. The file name comes as an argument at the end. Example (after line 5): 5r ~/template.txt If your text is in a register, you can use :put with a line number (again) in the range position and the register name (including , which must be escaped as \, for the default register; or + for the system clipboard) after the :put. Example (before cursor line): .-1put \ See :help :read :help :put Best regards, Tony. Hi Tony, thank you for your reply ! :) No, sorry...I was simply searching for a function call like printf( This is my text! ) but instead of C and printing onto stdout it should be vim-script and the text should go right at the current cursor position. Thats all. No registers, no script magic, not extra files. Simply put a string after the cursor into the text. Keep hacking! mcc (Untested): Characterwise: exe normal aThis is my text!\Esc Linewise: exe normal oThis is my text!\Esc If I didn't goof, you can paste one of the above lines straight into your script (via the clipboard). Best regards, Tony. Hi Tony, this works so far...with an unwanted sideeffekt: Instead of This is my text! in my buffer I get This is my text!Esc in my text. When using exe normal aThis is my text!\Esc instead, vim says in the commandline: E121: Undefined variable: Esc E15 Invalid expression: normalaThis is my textEsc . No way out ? Kind regards, mcc
Re: How to insert text via script/function call ?
Meino Christian Cramer wrote: From: A.J.Mechelynck [EMAIL PROTECTED] Subject: Re: How to insert text via script/function call ? Date: Fri, 18 Aug 2006 18:05:13 +0200 Meino Christian Cramer wrote: From: A.J.Mechelynck [EMAIL PROTECTED] Subject: Re: How to insert text via script/function call ? Date: Fri, 18 Aug 2006 07:29:05 +0200 Meino Christian Cramer 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 If your text is in a file on its own, you can use :r with a line number (the number of the line after which to insert, or 0 for before first line, or . for after cursor line, or $ for after last line; default is after cursor line) in the range position, i.e. just before the r. The file name comes as an argument at the end. Example (after line 5): 5r ~/template.txt If your text is in a register, you can use :put with a line number (again) in the range position and the register name (including , which must be escaped as \, for the default register; or + for the system clipboard) after the :put. Example (before cursor line): .-1put \ See :help :read :help :put Best regards, Tony. Hi Tony, thank you for your reply ! :) No, sorry...I was simply searching for a function call like printf( This is my text! ) but instead of C and printing onto stdout it should be vim-script and the text should go right at the current cursor position. Thats all. No registers, no script magic, not extra files. Simply put a string after the cursor into the text. Keep hacking! mcc (Untested): Characterwise: exe normal aThis is my text!\Esc Linewise: exe normal oThis is my text!\Esc If I didn't goof, you can paste one of the above lines straight into your script (via the clipboard). Best regards, Tony. Hi Tony, this works so far...with an unwanted sideeffekt: Instead of This is my text! in my buffer I get This is my text!Esc in my text. I get the text properly inserted. Are you sure that you used double quotes around the string and that it ended (before the closing double quote) with backslash, less-than, E-for-Echo, s-for-Sierra, c-for-Charlie, greater-than ? If it didn't, then you didn't use the lines above by copy-paste as I told you. Or else, maybe you have 'compatible' set? (check it by :verbose set compatible? without the quotes but with the question mark). When using exe normal aThis is my text!\Esc instead, vim says in the commandline: E121: Undefined variable: Esc E15 Invalid expression: normalaThis is my textEsc . No way out ? Kind regards, mcc Try :exe normal aThis is my text!\e and make sure that you use double quotes, not single quotes. see :help expr-string Best regards, Tony.
Re: How to insert text via script/function call ?
Meino Christian Cramer 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 If your text is in a file on its own, you can use :r with a line number (the number of the line after which to insert, or 0 for before first line, or . for after cursor line, or $ for after last line; default is after cursor line) in the range position, i.e. just before the r. The file name comes as an argument at the end. Example (after line 5): 5r ~/template.txt If your text is in a register, you can use :put with a line number (again) in the range position and the register name (including , which must be escaped as \, for the default register; or + for the system clipboard) after the :put. Example (before cursor line): .-1put \ See :help :read :help :put Best regards, Tony.