Mercurial > vim
annotate runtime/doc/if_perl.txt @ 19760:9daed26b788b v8.2.0436
patch 8.2.0436: no warnings for incorrect printf arguments
Commit: https://github.com/vim/vim/commit/db99f9f29a248b84742b6779c3343123f72065e7
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Mar 23 22:12:22 2020 +0100
patch 8.2.0436: no warnings for incorrect printf arguments
Problem: No warnings for incorrect printf arguments.
Solution: Fix attribute in declaration. Fix uncovered mistakes. (Dominique
Pelle, closes #5834)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 23 Mar 2020 22:15:05 +0100 |
parents | af69c9335223 |
children | 04ef2ccf2519 |
rev | line source |
---|---|
18879 | 1 *if_perl.txt* For Vim version 8.2. Last change: 2019 Dec 07 |
7 | 2 |
3 | |
4 VIM REFERENCE MANUAL by Sven Verdoolaege | |
5 and Matt Gerassimof | |
6 | |
7 Perl and Vim *perl* *Perl* | |
8 | |
9 1. Editing Perl files |perl-editing| | |
11473 | 10 2. Compiling Vim with Perl interface |perl-compiling| |
7 | 11 3. Using the Perl interface |perl-using| |
557 | 12 4. Dynamic loading |perl-dynamic| |
7 | 13 |
16553
0e473e9e70c2
patch 8.1.1280: remarks about functionality not in Vi clutters the help
Bram Moolenaar <Bram@vim.org>
parents:
15729
diff
changeset
|
14 {only available when Vim was compiled with the |+perl| feature} |
7 | 15 |
16 ============================================================================== | |
17 1. Editing Perl files *perl-editing* | |
18 | |
19 Vim syntax highlighting supports Perl and POD files. Vim assumes a file is | |
236 | 20 Perl code if the filename has a .pl or .pm suffix. Vim also examines the first |
7 | 21 line of a file, regardless of the filename suffix, to check if a file is a |
22 Perl script (see scripts.vim in Vim's syntax directory). Vim assumes a file | |
23 is POD text if the filename has a .POD suffix. | |
24 | |
25 To use tags with Perl, you need a recent version of Exuberant ctags. Look | |
26 here: | |
27 http://ctags.sourceforge.net | |
28 | |
29 Alternatively, you can use the Perl script pltags.pl, which is shipped with | |
30 Vim in the $VIMRUNTIME/tools directory. This script has currently more | |
31 features than Exuberant ctags' Perl support. | |
32 | |
33 ============================================================================== | |
11473 | 34 2. Compiling Vim with Perl interface *perl-compiling* |
7 | 35 |
36 To compile Vim with Perl interface, you need Perl 5.004 (or later). Perl must | |
37 be installed before you compile Vim. Vim's Perl interface does NOT work with | |
38 the 5.003 version that has been officially released! It will probably work | |
39 with Perl 5.003_05 and later. | |
40 | |
41 The Perl patches for Vim were made by: | |
42 Sven Verdoolaege <skimo@breughel.ufsia.ac.be> | |
43 Matt Gerassimof | |
44 | |
14432 | 45 Perl for MS-Windows (and other platforms) can be found at: |
15033 | 46 http://www.perl.org/ |
47 The ActiveState one should work, Strawberry Perl is a good alternative. | |
7 | 48 |
49 ============================================================================== | |
50 3. Using the Perl interface *perl-using* | |
51 | |
52 *:perl* *:pe* | |
236 | 53 :pe[rl] {cmd} Execute Perl command {cmd}. The current package |
3750 | 54 is "main". Simple example to test if `:perl` is |
55 working: > | |
56 :perl VIM::Msg("Hello") | |
7 | 57 |
18343 | 58 :pe[rl] << [endmarker] |
7 | 59 {script} |
18343 | 60 {endmarker} |
7 | 61 Execute Perl script {script}. |
18343 | 62 The {endmarker} after {script} must NOT be preceded by |
63 any white space. | |
17571 | 64 |
18343 | 65 If [endmarker] is omitted, it defaults to a dot '.' |
7 | 66 like for the |:append| and |:insert| commands. Using |
67 '.' helps when inside a function, because "$i;" looks | |
68 like the start of an |:insert| command to Vim. | |
17571 | 69 |
7 | 70 This form of the |:perl| command is mainly useful for |
71 including perl code in vim scripts. | |
72 Note: This command doesn't work when the Perl feature | |
73 wasn't compiled in. To avoid errors, see | |
74 |script-here|. | |
75 | |
76 | |
77 Example vim script: > | |
78 | |
79 function! WhitePearl() | |
80 perl << EOF | |
81 VIM::Msg("pearls are nice for necklaces"); | |
82 VIM::Msg("rubys for rings"); | |
83 VIM::Msg("pythons for bags"); | |
84 VIM::Msg("tcls????"); | |
85 EOF | |
86 endfunction | |
87 < | |
10153
715d6c5707b8
commit https://github.com/vim/vim/commit/abd468ed0fbcba391e7833feeaa7de3ced841455
Christian Brabandt <cb@256bit.org>
parents:
8673
diff
changeset
|
88 To see what version of Perl you have: > |
715d6c5707b8
commit https://github.com/vim/vim/commit/abd468ed0fbcba391e7833feeaa7de3ced841455
Christian Brabandt <cb@256bit.org>
parents:
8673
diff
changeset
|
89 :perl print $^V |
715d6c5707b8
commit https://github.com/vim/vim/commit/abd468ed0fbcba391e7833feeaa7de3ced841455
Christian Brabandt <cb@256bit.org>
parents:
8673
diff
changeset
|
90 < |
7 | 91 |
92 *:perldo* *:perld* | |
93 :[range]perld[o] {cmd} Execute Perl command {cmd} for each line in the | |
94 [range], with $_ being set to the text of each line in | |
236 | 95 turn, without a trailing <EOL>. Setting $_ will change |
7 | 96 the text, but note that it is not possible to add or |
97 delete lines using this command. | |
98 The default for [range] is the whole file: "1,$". | |
99 | |
100 Here are some things you can try: > | |
101 | |
102 :perl $a=1 | |
103 :perldo $_ = reverse($_);1 | |
104 :perl VIM::Msg("hello") | |
105 :perl $line = $curbuf->Get(42) | |
106 < | |
107 *E299* | |
108 Executing Perl commands in the |sandbox| is limited. ":perldo" will not be | |
109 possible at all. ":perl" will be evaluated in the Safe environment, if | |
110 possible. | |
111 | |
112 | |
113 *perl-overview* | |
114 Here is an overview of the functions that are available to Perl: > | |
115 | |
116 :perl VIM::Msg("Text") # displays a message | |
12968 | 117 :perl VIM::Msg("Wrong!", "ErrorMsg") # displays an error message |
7 | 118 :perl VIM::Msg("remark", "Comment") # displays a highlighted message |
119 :perl VIM::SetOption("ai") # sets a vim option | |
120 :perl $nbuf = VIM::Buffers() # returns the number of buffers | |
121 :perl @buflist = VIM::Buffers() # returns array of all buffers | |
122 :perl $mybuf = (VIM::Buffers('qq.c'))[0] # returns buffer object for 'qq.c' | |
123 :perl @winlist = VIM::Windows() # returns array of all windows | |
124 :perl $nwin = VIM::Windows() # returns the number of windows | |
125 :perl ($success, $v) = VIM::Eval('&path') # $v: option 'path', $success: 1 | |
126 :perl ($success, $v) = VIM::Eval('&xyz') # $v: '' and $success: 0 | |
127 :perl $v = VIM::Eval('expand("<cfile>")') # expands <cfile> | |
128 :perl $curwin->SetHeight(10) # sets the window height | |
129 :perl @pos = $curwin->Cursor() # returns (row, col) array | |
130 :perl @pos = (10, 10) | |
131 :perl $curwin->Cursor(@pos) # sets cursor to @pos | |
132 :perl $curwin->Cursor(10,10) # sets cursor to row 10 col 10 | |
133 :perl $mybuf = $curwin->Buffer() # returns the buffer object for window | |
134 :perl $curbuf->Name() # returns buffer name | |
135 :perl $curbuf->Number() # returns buffer number | |
136 :perl $curbuf->Count() # returns the number of lines | |
137 :perl $l = $curbuf->Get(10) # returns line 10 | |
138 :perl @l = $curbuf->Get(1 .. 5) # returns lines 1 through 5 | |
139 :perl $curbuf->Delete(10) # deletes line 10 | |
140 :perl $curbuf->Delete(10, 20) # delete lines 10 through 20 | |
141 :perl $curbuf->Append(10, "Line") # appends a line | |
142 :perl $curbuf->Append(10, "Line1", "Line2", "Line3") # appends 3 lines | |
143 :perl @l = ("L1", "L2", "L3") | |
144 :perl $curbuf->Append(10, @l) # appends L1, L2 and L3 | |
145 :perl $curbuf->Set(10, "Line") # replaces line 10 | |
146 :perl $curbuf->Set(10, "Line1", "Line2") # replaces lines 10 and 11 | |
147 :perl $curbuf->Set(10, @l) # replaces 3 lines | |
148 < | |
149 *perl-Msg* | |
150 VIM::Msg({msg}, {group}?) | |
151 Displays the message {msg}. The optional {group} | |
152 argument specifies a highlight group for Vim to use | |
153 for the message. | |
154 | |
155 *perl-SetOption* | |
156 VIM::SetOption({arg}) Sets a vim option. {arg} can be any argument that the | |
157 ":set" command accepts. Note that this means that no | |
158 spaces are allowed in the argument! See |:set|. | |
159 | |
160 *perl-Buffers* | |
161 VIM::Buffers([{bn}...]) With no arguments, returns a list of all the buffers | |
162 in an array context or returns the number of buffers | |
163 in a scalar context. For a list of buffer names or | |
164 numbers {bn}, returns a list of the buffers matching | |
165 {bn}, using the same rules as Vim's internal | |
166 |bufname()| function. | |
22 | 167 WARNING: the list becomes invalid when |:bwipe| is |
168 used. Using it anyway may crash Vim. | |
7 | 169 |
170 *perl-Windows* | |
171 VIM::Windows([{wn}...]) With no arguments, returns a list of all the windows | |
172 in an array context or returns the number of windows | |
173 in a scalar context. For a list of window numbers | |
174 {wn}, returns a list of the windows with those | |
175 numbers. | |
22 | 176 WARNING: the list becomes invalid when a window is |
177 closed. Using it anyway may crash Vim. | |
7 | 178 |
179 *perl-DoCommand* | |
180 VIM::DoCommand({cmd}) Executes Ex command {cmd}. | |
181 | |
182 *perl-Eval* | |
18831 | 183 VIM::Eval({expr}) Evaluates {expr} and returns (success, value) in list |
3920 | 184 context or just value in scalar context. |
7 | 185 success=1 indicates that val contains the value of |
186 {expr}; success=0 indicates a failure to evaluate | |
187 the expression. '@x' returns the contents of register | |
188 x, '&x' returns the value of option x, 'x' returns the | |
189 value of internal |variables| x, and '$x' is equivalent | |
190 to perl's $ENV{x}. All |functions| accessible from | |
191 the command-line are valid for {expr}. | |
714 | 192 A |List| is turned into a string by joining the items |
193 and inserting line breaks. | |
7 | 194 |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15033
diff
changeset
|
195 *perl-Blob* |
15729 | 196 VIM::Blob({expr}) Return |Blob| literal string 0zXXXX from scalar value. |
15454
1d2b5c016f17
patch 8.1.0735: cannot handle binary data
Bram Moolenaar <Bram@vim.org>
parents:
15033
diff
changeset
|
197 |
7 | 198 *perl-SetHeight* |
199 Window->SetHeight({height}) | |
200 Sets the Window height to {height}, within screen | |
201 limits. | |
202 | |
203 *perl-GetCursor* | |
204 Window->Cursor({row}?, {col}?) | |
205 With no arguments, returns a (row, col) array for the | |
206 current cursor position in the Window. With {row} and | |
207 {col} arguments, sets the Window's cursor position to | |
208 {row} and {col}. Note that {col} is numbered from 0, | |
209 Perl-fashion, and thus is one less than the value in | |
210 Vim's ruler. | |
211 | |
212 Window->Buffer() *perl-Buffer* | |
213 Returns the Buffer object corresponding to the given | |
214 Window. | |
215 | |
216 *perl-Name* | |
217 Buffer->Name() Returns the filename for the Buffer. | |
218 | |
219 *perl-Number* | |
220 Buffer->Number() Returns the number of the Buffer. | |
221 | |
222 *perl-Count* | |
223 Buffer->Count() Returns the number of lines in the Buffer. | |
224 | |
225 *perl-Get* | |
226 Buffer->Get({lnum}, {lnum}?, ...) | |
227 Returns a text string of line {lnum} in the Buffer | |
236 | 228 for each {lnum} specified. An array can be passed |
7 | 229 with a list of {lnum}'s specified. |
230 | |
231 *perl-Delete* | |
232 Buffer->Delete({lnum}, {lnum}?) | |
233 Deletes line {lnum} in the Buffer. With the second | |
234 {lnum}, deletes the range of lines from the first | |
235 {lnum} to the second {lnum}. | |
236 | |
237 *perl-Append* | |
238 Buffer->Append({lnum}, {line}, {line}?, ...) | |
239 Appends each {line} string after Buffer line {lnum}. | |
240 The list of {line}s can be an array. | |
241 | |
242 *perl-Set* | |
243 Buffer->Set({lnum}, {line}, {line}?, ...) | |
244 Replaces one or more Buffer lines with specified | |
245 {lines}s, starting at Buffer line {lnum}. The list of | |
246 {line}s can be an array. If the arguments are | |
247 invalid, replacement does not occur. | |
248 | |
249 $main::curwin | |
250 The current window object. | |
251 | |
252 $main::curbuf | |
253 The current buffer object. | |
254 | |
255 | |
256 *script-here* | |
257 When using a script language in-line, you might want to skip this when the | |
258 language isn't supported. But this mechanism doesn't work: > | |
259 if has('perl') | |
260 perl << EOF | |
261 this will NOT work! | |
262 EOF | |
263 endif | |
264 Instead, put the Perl/Python/Ruby/etc. command in a function and call that | |
265 function: > | |
266 if has('perl') | |
267 function DefPerl() | |
268 perl << EOF | |
269 this works | |
270 EOF | |
271 endfunction | |
272 call DefPerl() | |
273 endif | |
274 Note that "EOF" must be at the start of the line. | |
275 | |
557 | 276 ============================================================================== |
277 4. Dynamic loading *perl-dynamic* | |
278 | |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2365
diff
changeset
|
279 On MS-Windows and Unix the Perl library can be loaded dynamically. The |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2365
diff
changeset
|
280 |:version| output then includes |+perl/dyn|. |
557 | 281 |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2365
diff
changeset
|
282 This means that Vim will search for the Perl DLL or shared library file only |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2365
diff
changeset
|
283 when needed. When you don't use the Perl interface you don't need it, thus |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2365
diff
changeset
|
284 you can use Vim without this file. |
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2365
diff
changeset
|
285 |
557 | 286 |
2370
454f314d0e61
Make it possible to load Perl dynamically on Unix. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2365
diff
changeset
|
287 MS-Windows ~ |
557 | 288 |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
289 You can download Perl from http://www.perl.org. The one from ActiveState was |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
290 used for building Vim. |
557 | 291 |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
292 To use the Perl interface the Perl DLL must be in your search path. |
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
293 If Vim reports it cannot find the perl512.dll, make sure your $PATH includes |
2355
84c7eeeb09e2
Fix typos in documentation. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2345
diff
changeset
|
294 the directory where it is located. The Perl installer normally does that. |
8673
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
295 In a console window type "path" to see what directories are used. The |
ed7251c3e2d3
commit https://github.com/vim/vim/commit/e18c0b39815c5a746887a509c2cd9f11fadaba07
Christian Brabandt <cb@256bit.org>
parents:
7196
diff
changeset
|
296 'perldll' option can be also used to specify the Perl DLL. |
557 | 297 |
298 The name of the DLL must match the Perl version Vim was compiled with. | |
2342
f6540762173d
Fixes and improvements for MS-Windows build.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
299 Currently the name is "perl512.dll". That is for Perl 5.12. To know for |
557 | 300 sure edit "gvim.exe" and search for "perl\d*.dll\c". |
301 | |
7196
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5400
diff
changeset
|
302 |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5400
diff
changeset
|
303 Unix ~ |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5400
diff
changeset
|
304 |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5400
diff
changeset
|
305 The 'perldll' option can be used to specify the Perl shared library file |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5400
diff
changeset
|
306 instead of DYNAMIC_PERL_DLL file what was specified at compile time. The |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5400
diff
changeset
|
307 version of the shared library must match the Perl version Vim was compiled |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5400
diff
changeset
|
308 with. |
42717d048817
commit https://github.com/vim/vim/commit/d94464ee294a351ce7b6ba18e8bd3f24f1bef920
Christian Brabandt <cb@256bit.org>
parents:
5400
diff
changeset
|
309 |
557 | 310 ============================================================================== |
14421 | 311 vim:tw=78:ts=8:noet:ft=help:norl: |