Mercurial > vim
comparison runtime/doc/if_pyth.txt @ 236:4707450c2b33
updated for version 7.0066
author | vimboss |
---|---|
date | Fri, 15 Apr 2005 21:00:38 +0000 |
parents | 4ac1dce8dd5e |
children | 862863033fdd |
comparison
equal
deleted
inserted
replaced
235:23d380e32c95 | 236:4707450c2b33 |
---|---|
1 *if_pyth.txt* For Vim version 7.0aa. Last change: 2004 Jul 25 | 1 *if_pyth.txt* For Vim version 7.0aa. Last change: 2005 Mar 29 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Paul Moore | 4 VIM REFERENCE MANUAL by Paul Moore |
5 | 5 |
6 | 6 |
83 | 83 |
84 ============================================================================== | 84 ============================================================================== |
85 2. The vim module *python-vim* | 85 2. The vim module *python-vim* |
86 | 86 |
87 Python code gets all of its access to vim (with one exception - see | 87 Python code gets all of its access to vim (with one exception - see |
88 |python-output| below) via the "vim" module. The vim module implements two | 88 |python-output| below) via the "vim" module. The vim module implements two |
89 methods, three constants, and one error object. You need to import the vim | 89 methods, three constants, and one error object. You need to import the vim |
90 module before using it: > | 90 module before using it: > |
91 :python import vim | 91 :python import vim |
92 | 92 |
93 Overview > | 93 Overview > |
111 | 111 |
112 | 112 |
113 Methods of the "vim" module | 113 Methods of the "vim" module |
114 | 114 |
115 vim.command(str) *python-command* | 115 vim.command(str) *python-command* |
116 Executes the vim (ex-mode) command str. Returns None. | 116 Executes the vim (ex-mode) command str. Returns None. |
117 Examples: > | 117 Examples: > |
118 :py vim.command("set tw=72") | 118 :py vim.command("set tw=72") |
119 :py vim.command("%s/aaa/bbb/g") | 119 :py vim.command("%s/aaa/bbb/g") |
120 < The following definition executes Normal mode commands: > | 120 < The following definition executes Normal mode commands: > |
121 def normal(str): | 121 def normal(str): |
128 older. This only works with Python 2.3 and later: > | 128 older. This only works with Python 2.3 and later: > |
129 :py vim.command("python print 'Hello again Python'") | 129 :py vim.command("python print 'Hello again Python'") |
130 | 130 |
131 vim.eval(str) *python-eval* | 131 vim.eval(str) *python-eval* |
132 Evaluates the expression str using the vim internal expression | 132 Evaluates the expression str using the vim internal expression |
133 evaluator (see |expression|). Returns the expression result as a | 133 evaluator (see |expression|). Returns the expression result as a |
134 string. | 134 string. |
135 Examples: > | 135 Examples: > |
136 :py text_width = vim.eval("&tw") | 136 :py text_width = vim.eval("&tw") |
137 :py str = vim.eval("12+12") # NB result is a string! Use | 137 :py str = vim.eval("12+12") # NB result is a string! Use |
138 # string.atoi() to convert to | 138 # string.atoi() to convert to |
154 Note that these are not actually constants - you could reassign them. | 154 Note that these are not actually constants - you could reassign them. |
155 But this is silly, as you would then lose access to the vim objects | 155 But this is silly, as you would then lose access to the vim objects |
156 to which the variables referred. | 156 to which the variables referred. |
157 | 157 |
158 vim.buffers *python-buffers* | 158 vim.buffers *python-buffers* |
159 A sequence object providing access to the list of vim buffers. The | 159 A sequence object providing access to the list of vim buffers. The |
160 object supports the following operations: > | 160 object supports the following operations: > |
161 :py b = vim.buffers[i] # Indexing (read-only) | 161 :py b = vim.buffers[i] # Indexing (read-only) |
162 :py b in vim.buffers # Membership test | 162 :py b in vim.buffers # Membership test |
163 :py n = len(vim.buffers) # Number of elements | 163 :py n = len(vim.buffers) # Number of elements |
164 :py for b in vim.buffers: # Sequential access | 164 :py for b in vim.buffers: # Sequential access |
165 < | 165 < |
166 vim.windows *python-windows* | 166 vim.windows *python-windows* |
167 A sequence object providing access to the list of vim windows. The | 167 A sequence object providing access to the list of vim windows. The |
168 object supports the following operations: > | 168 object supports the following operations: > |
169 :py w = vim.windows[i] # Indexing (read-only) | 169 :py w = vim.windows[i] # Indexing (read-only) |
170 :py w in vim.windows # Membership test | 170 :py w in vim.windows # Membership test |
171 :py n = len(vim.windows) # Number of elements | 171 :py n = len(vim.windows) # Number of elements |
172 :py for w in vim.windows: # Sequential access | 172 :py for w in vim.windows: # Sequential access |
177 vim.current.line The current line (RW) String | 177 vim.current.line The current line (RW) String |
178 vim.current.buffer The current buffer (RO) Buffer | 178 vim.current.buffer The current buffer (RO) Buffer |
179 vim.current.window The current window (RO) Window | 179 vim.current.window The current window (RO) Window |
180 vim.current.range The current line range (RO) Range | 180 vim.current.range The current line range (RO) Range |
181 | 181 |
182 The last case deserves a little explanation. When the :python or | 182 The last case deserves a little explanation. When the :python or |
183 :pyfile command specifies a range, this range of lines becomes the | 183 :pyfile command specifies a range, this range of lines becomes the |
184 "current range". A range is a bit like a buffer, but with all access | 184 "current range". A range is a bit like a buffer, but with all access |
185 restricted to a subset of lines. See |python-range| for more details. | 185 restricted to a subset of lines. See |python-range| for more details. |
186 | 186 |
187 | 187 |
188 Output from Python *python-output* | 188 Output from Python *python-output* |
189 Vim displays all Python code output in the Vim message area. Normal | 189 Vim displays all Python code output in the Vim message area. Normal |
190 output appears as information messages, and error output appears as | 190 output appears as information messages, and error output appears as |
195 messages, and all output to sys.stderr (including error tracebacks) | 195 messages, and all output to sys.stderr (including error tracebacks) |
196 appears as error messages. | 196 appears as error messages. |
197 | 197 |
198 *python-input* | 198 *python-input* |
199 Input (via sys.stdin, including input() and raw_input()) is not | 199 Input (via sys.stdin, including input() and raw_input()) is not |
200 supported, and may cause the program to crash. This should probably be | 200 supported, and may cause the program to crash. This should probably be |
201 fixed. | 201 fixed. |
202 | 202 |
203 ============================================================================== | 203 ============================================================================== |
204 3. Buffer objects *python-buffer* | 204 3. Buffer objects *python-buffer* |
205 | 205 |
206 Buffer objects represent vim buffers. You can obtain them in a number of ways: | 206 Buffer objects represent vim buffers. You can obtain them in a number of ways: |
207 - via vim.current.buffer (|python-current|) | 207 - via vim.current.buffer (|python-current|) |
208 - from indexing vim.buffers (|python-buffers|) | 208 - from indexing vim.buffers (|python-buffers|) |
209 - from the "buffer" attribute of a window (|python-window|) | 209 - from the "buffer" attribute of a window (|python-window|) |
210 | 210 |
211 Buffer objects have one read-only attribute - name - the full file name for | 211 Buffer objects have one read-only attribute - name - the full file name for |
212 the buffer. They also have three methods (append, mark, and range; see below). | 212 the buffer. They also have three methods (append, mark, and range; see below). |
213 | 213 |
214 You can also treat buffer objects as sequence objects. In this context, they | 214 You can also treat buffer objects as sequence objects. In this context, they |
215 act as if they were lists (yes, they are mutable) of strings, with each | 215 act as if they were lists (yes, they are mutable) of strings, with each |
216 element being a line of the buffer. All of the usual sequence operations, | 216 element being a line of the buffer. All of the usual sequence operations, |
217 including indexing, index assignment, slicing and slice assignment, work as | 217 including indexing, index assignment, slicing and slice assignment, work as |
218 you would expect. Note that the result of indexing (slicing) a buffer is a | 218 you would expect. Note that the result of indexing (slicing) a buffer is a |
219 string (list of strings). This has one unusual consequence - b[:] is different | 219 string (list of strings). This has one unusual consequence - b[:] is different |
220 from b. In particular, "b[:] = None" deletes the whole of the buffer, whereas | 220 from b. In particular, "b[:] = None" deletes the whole of the buffer, whereas |
221 "b = None" merely updates the variable b, with no effect on the buffer. | 221 "b = None" merely updates the variable b, with no effect on the buffer. |
222 | 222 |
223 Buffer indexes start at zero, as is normal in Python. This differs from vim | 223 Buffer indexes start at zero, as is normal in Python. This differs from vim |
224 line numbers, which start from 1. This is particularly relevant when dealing | 224 line numbers, which start from 1. This is particularly relevant when dealing |
225 with marks (see below) which use vim line numbers. | 225 with marks (see below) which use vim line numbers. |
226 | 226 |
227 The buffer object methods are: | 227 The buffer object methods are: |
228 b.append(str) Append a line to the buffer | 228 b.append(str) Append a line to the buffer |
229 b.append(list) Append a list of lines to the buffer | 229 b.append(list) Append a list of lines to the buffer |
253 :py r = b.range(1,5) # a sub-range of the buffer | 253 :py r = b.range(1,5) # a sub-range of the buffer |
254 | 254 |
255 ============================================================================== | 255 ============================================================================== |
256 4. Range objects *python-range* | 256 4. Range objects *python-range* |
257 | 257 |
258 Range objects represent a part of a vim buffer. You can obtain them in a | 258 Range objects represent a part of a vim buffer. You can obtain them in a |
259 number of ways: | 259 number of ways: |
260 - via vim.current.range (|python-current|) | 260 - via vim.current.range (|python-current|) |
261 - from a buffer's range() method (|python-buffer|) | 261 - from a buffer's range() method (|python-buffer|) |
262 | 262 |
263 A range object is almost identical in operation to a buffer object. However, | 263 A range object is almost identical in operation to a buffer object. However, |
264 all operations are restricted to the lines within the range (this line range | 264 all operations are restricted to the lines within the range (this line range |
265 can, of course, change as a result of slice assignments, line deletions, or | 265 can, of course, change as a result of slice assignments, line deletions, or |
266 the range.append() method). | 266 the range.append() method). |
267 | 267 |
268 The range object attributes are: | 268 The range object attributes are: |
281 vim.command("%d,%dhardcopy!" % (r.start+1,r.end+1)) | 281 vim.command("%d,%dhardcopy!" % (r.start+1,r.end+1)) |
282 | 282 |
283 ============================================================================== | 283 ============================================================================== |
284 5. Window objects *python-window* | 284 5. Window objects *python-window* |
285 | 285 |
286 Window objects represent vim windows. You can obtain them in a number of ways: | 286 Window objects represent vim windows. You can obtain them in a number of ways: |
287 - via vim.current.window (|python-current|) | 287 - via vim.current.window (|python-current|) |
288 - from indexing vim.windows (|python-windows|) | 288 - from indexing vim.windows (|python-windows|) |
289 | 289 |
290 You can manipulate window objects only through their attributes. They have no | 290 You can manipulate window objects only through their attributes. They have no |
291 methods, and no sequence or other interface. | 291 methods, and no sequence or other interface. |
292 | 292 |
293 Window attributes are: | 293 Window attributes are: |
294 buffer (read-only) The buffer displayed in this window | 294 buffer (read-only) The buffer displayed in this window |
295 cursor (read-write) The current cursor position in the window | 295 cursor (read-write) The current cursor position in the window |